获取 java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21699061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:08:48  来源:igfitidea点击:

Getting java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

javaandroid

提问by Viresh

I am new to android. I am getting an error while updating through HttpClient like java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

我是安卓新手。通过 HttpClient 更新时出现错误,例如 java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

public static String newupdateProf(String memid, String gender,
                String pdata, String dob, String pimg) throws IOException,
                JSONException {
            // System.setProperty("http.keepAlive", "false");
            final HttpClient httpClient = new DefaultHttpClient();
            final HttpPost httpost = new HttpPost(websrv.trim() + "/newUpdtProf");

            JSONStringer img = new JSONStringer().object().key("prof").object()
                    .key("memid").value(memid.trim()).key("gender")
                    .value(gender.trim()).key("pdata").value(pdata.trim())
                    .key("dob").value(dob.trim()).key("pimg").value(pimg.trim())
                    .endObject().endObject();
            StringEntity se = new StringEntity(img.toString());
            httpost.setEntity(se);
            httpost.setHeader("Accept", "application/json");
            httpost.setHeader("Content-type", "application/json");

            HttpResponse httpResponse = httpClient.execute(httpost);

            HttpEntity httpEntity = httpResponse.getEntity();

            InputStream stream = httpEntity.getContent();
            String result = convertStreamToString(stream);
            return result.trim();

        }

Please help me. I also tried

请帮我。我也试过

System.setProperty("http.keepAlive", "false"); 

but it's not working.

但它不起作用。

回答by Lei Leyba

Set the http.keepAlive system property to false before issuing any HTTP requests.

在发出任何 HTTP 请求之前,将 http.keepAlive 系统属性设置为 false。

System.setProperty("http.keepAlive", "false");