【发布时间】:2014-07-15 07:25:40
【问题描述】:
我正在使用以下代码将图像发布到服务器,但它在下面给出错误
org.apache.http.NoHttpResponseException:目标服务器响应失败
我不明白问题是来自服务器端还是来自我的代码端。
谁能帮我解决这个问题?
代码:
protected Long doInBackground(URL... arg0) {
CustomMultiPartEntity multipartContent = new CustomMultiPartEntity(
new ProgressListener() {
@Override
public void transferred(long num) {
publishProgress((int) ((num / (float) totalSize) * 100));
}
});
try {
for (int i = Constants.IMAGE_SELECTION; i < al_image_paths
.size(); i++) {
count = i + 1;
progressDialog.setProgress(0);
// String url=DataUrl.hostId+"/addpost/postImageOrVideo?";
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(image_upload);
Log.e("strImagePath.... before uploading",
al_image_paths.get(i));
multipartContent.addPart("image", new FileBody(new File(
al_image_paths.get(i))));
multipartContent.addPart("sellleadid",
new StringBody(pref.getString("sellerID", "")));
multipartContent.addPart("action", new StringBody(
"Send Used Car Images"));
multipartContent.addPart("app_id", new StringBody(Constants.DEVICE_ID));
totalSize = multipartContent.getContentLength();
httpPost.setEntity(multipartContent);
HttpResponse response = httpClient.execute(httpPost,
localContext);
String serverResponse = EntityUtils.toString(response
.getEntity());
Log.e("serverResponse image", "<> " + serverResponse);
JSONObject object = new JSONObject(serverResponse);
if (object.getString("status").equals("200")) {
selectedImageIds.add(object.getString("imageid"));
selectedUrls.add(object.getString("url"));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}`enter code here`
【问题讨论】:
-
哪一行会抛出 NoHttpResponseException?
标签: android