gpt4 book ai didi

android - org.apache.http.NoHttpResponseException : The target server failed to respond

转载 作者:行者123 更新时间:2023-12-04 18:06:47 56 4
gpt4 key购买 nike

我正在使用下面的代码将图像发布到服务器,但它在下面给出了错误

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`

最佳答案

确保您在 list 文件中拥有 android.permission.INTERNET 权限。

同时检查 - Apache HttpClient Interim Error: NoHttpResponseException .

编辑:

java.io.IOException
+- org.apache.commons.httpclient.NoHttpResponseException

In some circumstances, usually when under heavy load, the web server may be able to receive requests but unable to process them. A lack of sufficient resources like worker threads is a good example. This may cause the server to drop the connection to the client without giving any response. HttpClient throws NoHttpResponseException when it encounters such a condition. In most cases it is safe to retry a method that failed with NoHttpResponseException.

来源: http://hc.apache.org/httpclient-3.x/exception-handling.html

关于android - org.apache.http.NoHttpResponseException : The target server failed to respond,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24752278/

56 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com