这个问题已经有了答案:
Getting “SocketException : Connection reset by peer” in Android
5答
我是Android新手。
通过httpclient(如java.net.socketexception:recvfrom failed:econnreset)更新时,我收到一个错误(通过对等方重置连接)
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();
}
请帮帮我。
我也尝试过
System.setProperty("http.keepAlive", "false");
但没用。
最佳答案
在发出任何http请求之前,请将http.keepalive系统属性设置为false。
System.setProperty("http.keepAlive", "false");