アプリケーションの起動時に、さまざまなWebサービス(php)を約15回呼び出す必要があります。
投稿には次のコードを使用しています
public static String post(String url, List<BasicNameValuePair>
postvalues, HttpClient httpclient) {
try {
if (httpclient == null) {
httpclient = new DefaultHttpClient();
}
HttpPost httppost = new HttpPost(url);
if ((postvalues == null)) {
postvalues = new ArrayList<BasicNameValuePair>();
}
httppost.setEntity(new UrlEncodedFormEntity(postvalues, "UTF-8"));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
return requestToString(response);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static String requestToString(HttpResponse response) {
String result = "";
try {
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line + "\n");
}
in.close();
result = str.toString();
} catch (Exception ex) {
result = "Error";
}
return result;
}
問題は、いくつかの請願は特定の順序で要求されなければならず、各要求には約1〜2秒かかるため、「スプラッシュの読み込み」には約10秒かかることです。
だから私の質問は:すべての接続が同じサーバーにあるので、どうすればこの遅延を改善できますか?接続を開き、その「トンネル」を介してすべての請願を送信して遅延を減らす方法はありますか?
注:コードをテストしましたが、リクエストは、各接続で新しいものを使用してhttpclientを再利用するのに同時にかかります
ありがとう