httpclient, Jame 's Mime4J 및 HTTPPost 게시 방법을 사용하여 속도를 느리게합니다.

StackOverflow https://stackoverflow.com/questions/2227025

문제

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

이제 로그인 및 게시 작업 - 괜찮지 만 업로드는 고통스럽게 느립니다. 인터넷 연결을 테스트했는데 필요한 것보다 훨씬 느립니다 (대략 업 속도는 1MB/s입니다. 3MB 파일을 업로드하는 데 약 5 분이 걸립니다 (30 대가 아닌).

누구든지 아이디어가 있습니까?

도움이 되었습니까?

해결책

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();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top