【发布时间】:2014-03-09 01:46:59
【问题描述】:
我是安卓新手。 通过 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();
}
请帮助我。 我也试过了
System.setProperty("http.keepAlive", "false");
但它不起作用。
【问题讨论】:
-
答案是服务器的错——它必须在每次请求后关闭连接。可能是android保留了一个连接池并使用旧的连接池或类似的东西