2013-10-14 37 views
0

我創建了通過POST請求在Foursquare.com上登錄的方法。但我在這條線上有很大的延遲:通過HTTPS登錄的長POST請求android

conn.getResponseCode(); 

我需要等待一分鐘才能登錄。爲什麼會發生?

也許有一種方法可以快速POST請求?

代碼:

public void sendPost(String url, String postParams, String refererLink, String hostLink) throws Exception { 
     Log.d(LOG_TAG, "sendPost"); 
     URL obj = new URL(url); 
     conn = (HttpsURLConnection) obj.openConnection(); 

     // Acts like a browser 
     conn.setUseCaches(false); 
     conn.setRequestMethod("POST"); 
     conn.setRequestProperty("Host", hostLink); 
     conn.setRequestProperty("User-Agent", USER_AGENT); 
     conn.setRequestProperty("Accept", 
       "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); 
     conn.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); 
     this.cookies = new ArrayList<String>(); 
     for (String cookie : this.cookies) { 
      conn.addRequestProperty("Cookie", cookie.split(";", 1)[0]); 
     } 
     conn.setRequestProperty("Connection", "keep-alive"); 
     conn.setRequestProperty("Referer", refererLink); 
     conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
     conn.setRequestProperty("Content-Length", Integer.toString(postParams.length())); 

     conn.setDoOutput(true); 
     conn.setDoInput(true); 

     // Send post request 
     Log.d(LOG_TAG, "Send post request"); 
     DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); 
     wr.writeBytes(postParams); 
     wr.flush(); 
     wr.close(); 

     conn.getResponseCode(); 
    } 

回答

0

的解決方法是使用Jsoup庫提交\ GET請求。

當我使用它時,速度增長了大約80倍。

+0

你能多描述一下嗎? –

+0

我剛開始使用它。我不知道這個lib的技術實現。 – Val