我正在使用以下代码将图像发布到服务器,但它给出了以下错误:
org.apache.http.NoHttpResponseException:目标服务器未响应
我不知道问题是来自服务器方面还是我的代码方面。
有人可以帮我解决这个问题吗?
代码:
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`