Android 服务器禁止json请求上的IP
当我试图通过应用程序从服务器获取数据时,我的服务器会禁止IP 10分钟。 我有两台具有两个不同IP的设备。我尝试在浏览器中加载脚本:设备正确加载脚本。然后我尝试从应用程序中请求数据,之后在浏览器中我得到“主机不可用”,但第二台设备仍然正确地在浏览器中加载脚本,直到我尝试直接从应用程序加载数据。 我认为问题在于服务器收到特定数量的请求后自动进行的某种安全设置。 以下是来自cPanel的日志: 在apache设置中可能存在如下内容:Android 服务器禁止json请求上的IP,android,json,apache,cpanel,Android,Json,Apache,Cpanel,当我试图通过应用程序从服务器获取数据时,我的服务器会禁止IP 10分钟。 我有两台具有两个不同IP的设备。我尝试在浏览器中加载脚本:设备正确加载脚本。然后我尝试从应用程序中请求数据,之后在浏览器中我得到“主机不可用”,但第二台设备仍然正确地在浏览器中加载脚本,直到我尝试直接从应用程序加载数据。 我认为问题在于服务器收到特定数量的请求后自动进行的某种安全设置。 以下是来自cPanel的日志: 在apache设置中可能存在如下内容: if (browser == unknown || OS ==
if (browser == unknown || OS == unknown)
banIP(360000);
请求代码:
.......
JSONObject json = null;
List<NameValuePair> pn = new ArrayList<NameValuePair>();
pn.add(new BasicNameValuePair("pn", getApplication()
.getPackageName()));
try {
json = jParser.makeHttpRequest(
"http://nastynoises.shunamicode.com/getlastappversion/get_latest_app_version_v2.php","GET", pn);
} catch (Exception e) {
}
.......
服务器返回:
05-01 00:07:21.545: D/shunami(1087): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
05-01 00:07:21.545: D/shunami(1087): <html><head>
05-01 00:07:21.545: D/shunami(1087): <title>406 Not Acceptable</title>
05-01 00:07:21.545: D/shunami(1087): </head><body>
05-01 00:07:21.545: D/shunami(1087): <h1>Not Acceptable</h1>
05-01 00:07:21.545: D/shunami(1087): <p>An appropriate representation of the requested resource /getlastappversion/get_latest_app_version_v2.php could not be found on this server.</p>
05-01 00:07:21.545: D/shunami(1087): <p>Additionally, a 404 Not Found
05-01 00:07:21.545: D/shunami(1087): error was encountered while trying to use an ErrorDocument to handle the request.</p>
05-01 00:07:21.545: D/shunami(1087): </body></html>
05-01 00:07:21.545:D/shunami(1087):
05-01 00:07:21.545:D/shunami(1087):
05-01 00:07:21.545:D/shunami(1087):406不可接受
05-01 00:07:21.545:D/shunami(1087):
05-01 00:07:21.545:D/shunami(1087):不可接受
05-01 00:07:21.545:D/shunami(1087):在此服务器上找不到请求的资源/getlastappversion/get_LastAppVersion\u app_version\u v2.php的适当表示形式
05-01 00:07:21.545:D/shunami(1087):此外,未找到404
05-01 00:07:21.545:D/shunami(1087):尝试使用ErrorDocument处理请求时遇到错误
05-01 00:07:21.545:D/shunami(1087):
php:
我找到了一个解决方案。现在我的应用程序工作正常,就像以前一样。但这不可能是问题的答案,这是一个旁路:
设置BasicHttpParams()时服务器返回响应,因此JSONParser现在可以工作:
....
int TIMEOUT_MILLISEC = 10000;
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,
TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient httpClient = new DefaultHttpClient(httpParams);
....
问题仍然悬而未决
<?php
$response = array();
require_once __DIR__ . '/con.php';
$db = new DB_CONNECT();
if (isset($_GET["pn"])) {
$result = mysql_query("SELECT * FROM `latest_versions` WHERE `package_name` = '".$_GET["pn"]."'");
if (!empty($result)) {
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
$response["success"] = 1;
$response["version"] = $row['version'];
$response["approxdate"] = $row['approxdate'];
echo json_encode($response);
}
} else {
$response["success"] = 0;
$response["message"] = "Package not exist";
echo json_encode($response);
}
} else {
$response["success"] = 0;
$response["message"] = "Empty result";
echo json_encode($response);
}
} else {
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
echo json_encode($response);
}
?>
....
int TIMEOUT_MILLISEC = 10000;
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,
TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient httpClient = new DefaultHttpClient(httpParams);
....