Tôi đã cố gắng tải ảnh lên máy chủ bằng HttpClient trong điện thoại di động Android, nhưng đôi khi tôi gặp lỗi này, nó không xảy ra luôn. bất cứ ai biết làm thế nào để giải quyết nó?HttpPost không thành công do "Không thể thử yêu cầu với thực thể yêu cầu không lặp lại"
mã của tôi như:
HttpClient client =new DefaultHttpClient();
HttpPut httpPut = new HttpPut(uploadUrl);
InputStream in =null;
HttpResponse response =null;
try {
in = new FileInputStream(filepath);
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(in);
entity.setContentLength(new File(basepath+path).length());
httpPut.setEntity(entity);
response = client.execute(httpPut);
System.out.println(response.getStatusLine());
consume(response.getEntity());
}
.......
thông tin Lỗi:
11-22 10:32:50.370: W/System.err(15224): org.apache.http.client.ClientProtocolException
11-22 10:32:50.370: W/System.err(15224): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
11-22 10:32:50.370: W/System.err(15224): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-22 10:32:50.370: W/System.err(15224): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-22 10:32:50.370: W/System.err(15224): at com.hp.nimbus.android.skydrive.util.SkyDriveUtils_Rest.doUploadPhoto(SkyDriveUtils_Rest.java:203)
11-22 10:32:50.380: W/System.err(15224): at com.hp.nimbus.android.skydrive.util.SkyDriveUtils_Rest.uploadPhoto(SkyDriveUtils_Rest.java:250)
11-22 10:32:50.380: W/System.err(15224): at com.hp.nimbus.android.skydrive.FolderMonitorService$1.onEvent(FolderMonitorService.java:36)
11-22 10:32:50.380: W/System.err(15224): at android.os.FileObserver$ObserverThread.onEvent(FileObserver.java:125)
11-22 10:32:50.380: W/System.err(15224): at android.os.FileObserver$ObserverThread.observe(Native Method)
11-22 10:32:50.380: W/System.err(15224): at android.os.FileObserver$ObserverThread.run(FileObserver.java:88)
11-22 10:32:50.380: W/System.err(15224): Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
11-22 10:32:50.380: W/System.err(15224): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:419)
11-22 10:32:50.380: W/System.err(15224): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-22 10:32:50.390: W/System.err(15224): ... 8 more
Xin chào, cảm ơn câu trả lời của bạn. Tôi đã thử FileEntity trước đây, vấn đề là máy chủ tải lên không hỗ trợ FileEntity, tôi phải sử dụng FileInputStream. Và bạn đã đề cập đến yêu cầu ban đầu không thành công, có thể biết lý do cho sự thất bại này không? – user1059217
Không hỗ trợ 'FileEntity' âm thanh lẻ. Đối với một sửa chữa đơn giản, hãy thử gói thực thể của bạn trong một BufferedHttpEntity - điều này sẽ làm cho nó lặp lại nhưng nhai thông qua bộ nhớ nhiều hơn một chút làm như vậy. – Jens