2
httpclient.execute (httppost)를 사용하고 있으며 내 웹 서버에 작은 파일을 보내기 위해 약 10 초가 소요됩니다. 휴대 전화에서 웹 브라우저를 사용하여 동일한 파일을 업로드하면 1 초 이내에 완료됩니다. 여기 내 코드는안드로이드에서 httpclient.Execute가 매우 느립니다.
String urlString = "http://xxxxx/upload.php";
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
DefaultHttpClient httpclient = new DefaultHttpClient(params);
HttpPost httppost = new HttpPost(urlString);
File file = new File(pic);
Log.d(TAG, "UPLOAD: setting up multipart entity");
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
Log.d(TAG, "UPLOAD: file length = " + file.length());
Log.d(TAG, "UPLOAD: file exist = " + file.exists());
mpEntity.addPart("uploadedfile", new FileBody(file, "application/octet"));
// mpEntity.addPart("id", new StringBody("1"));
httppost.setEntity(mpEntity);
Log.d(TAG, "UPLOAD: executing request: " + httppost.getRequestLine());
Log.d(TAG, "UPLOAD: request: " + httppost.getEntity().getContentType().toString());
HttpResponse response;
try {
Log.d(TAG, "UPLOAD: about to execute");
response = httpclient.execute(httppost);
Log.d(TAG, "UPLOAD: executed");
HttpEntity resEntity = response.getEntity();
Log.d(TAG, "UPLOAD: respose code: " + response.getStatusLine().toString());
if (resEntity != null) {
Log.d(TAG, "UPLOAD: " + EntityUtils.toString(resEntity));
}
if (resEntity != null) {
resEntity.consumeContent();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
안드로이드에 버그가 있습니까 응용 프로그램에서 신속하게 파일의 업로드를 방지?
감사의
HttpUrlConnection
를 사용하는 것이 좋습니다. 나는 여기에 질문을 물었다. http://stackoverflow.com/questions/12581289/opening-datainputstream-running-very-slow. 해결책이없는 것처럼 다른 방법을 사용하기로 결정 했습니까? – user1197941아마도 도움이 될까요? http://stackoverflow.com/questions/1920623/sometimes-httpurlconnection-getinputstream-executes-too-slowly – vasart
감사합니다. 여전히 동일합니다. 업로드가 빠르게 발생하지만 응답을 읽는 데는 오래 걸립니다. – user1197941