2013-04-30 100 views
3

當我嘗試從應用程序獲取數據時,我的服務器禁止IP 10分鐘。 我有2個不同IP的設備。我嘗試在瀏覽器中加載腳本:設備正確加載它。然後我嘗試從應用程序請求數據,然後在瀏覽器中我得到「主機不可用」,但第二個設備仍然正確地在瀏覽器中加載腳本,直到我嘗試直接從應用程序加載數據。 我認爲問題出現在一些安全設置中,服務器獲取特定數量的請求後會自動進行安全設置。 下面是從的cPanel日誌:json請求服務器禁止IP

cpanel log

也許在Apache的設置存在這樣的事:請求

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) { 
     } 
....... 

製作要求的樣子:

http://nastynoises.shunamicode.com/getlastappversion/get_latest_app_version_v2.php?pn=com.shunamicode.nn

JsonParser:

makeHttpRequest(){ 
.... 
    DefaultHttpClient httpClient = new DefaultHttpClient(); 
    String paramString = URLEncodedUtils.format(params, "utf-8"); 
     url += "?" + paramString; 
    HttpGet httpGet = new HttpGet(url); 
    HttpResponse httpResponse = httpClient.execute(httpGet); 
    HttpEntity httpEntity = httpResponse.getEntity(); 
    is = httpEntity.getContent(); 
.... 
} 

服務器返回:

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> 

PHP:

<?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); 
} 
?> 

我試圖再次刪除所有腳本和請求,但是服務器仍然禁止。 我沒有很多練習,這個錯誤讓我陷入僵局。

回答

1

我找到了解決方案。現在我的應用程序可以正常工作但它不能是問題的答案,這是一個旁路:當我設置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); 
.... 

問題仍然是開放的