投稿のHttpClientを、ジェームズのMime4jとHttpPostメソッドを使用してスローアップロード速度
-
19-09-2019 - |
質問
私は次のようにメソッドを実行HttpPostを使用して、データのマルチチャンクをアップロードし、HttpClientをオブジェクトにそれを供給しますよ
HttpPost loginPost = new HttpPost(LOGIN_URL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("_email", mEmailAddress));
params.add(new BasicNameValuePair("lpassword", mPassword));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
loginPost.setEntity(entity);
HttpResponse resp = mHttpClient.execute(loginPost);
HttpPost post = new HttpPost(UPLOAD_URL);
FileBody bin = new FileBody(file);
MultipartEntity me = new MultipartEntity();
me.addPart("stuff", new StringBody(stuff));
me.addPart("file", bin);
post.setEntity(new RequestEntityEx(me, handler));
mHttpClient.execute(post);
さて、ログインして作業を掲示 - 罰金が、アップロードは痛々しいほど遅いです。私は私のインターネット接続をテストしてみたし、それはそれは約(どうあるべきかよりもはるかに遅いです。アップ速度が3メガバイトのファイルをアップロードし、1MB /秒である)ではなく30代以上(約5分を取ってます。
誰もが任意のアイデアがありますか?
解決
私はHttpClientをがhttpsで通常の方法よりも遅く9倍のようなものであることを発見しました。私は誰が悪いのかを知っている理由は、見当がつかないます。
ここでは、基本的に私のコードです。
private static HttpClient httpClient = new DefaultHttpClient();
private static HttpPost httpPost = new HttpPost(RRD_URL);
public static String sendData(List<NameValuePair> data) {
StringBuffer buffer = new StringBuffer();
BufferedReader rd = null;
try {
httpPost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse httpResponse = httpClient.execute(httpPost);
rd = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
String line;
while ((line = rd.readLine()) != null) {
buffer.append(line);
}
} catch (IOException e) {
e.printStackTrace(System.out);
} finally {
try {
if (rd != null) {
rd.close();
}
} catch (IOException e) {
e.printStackTrace(System.out);
}
}
return buffer.toString();
}
所属していません StackOverflow