我已经搜索了很多这个异常,很少发生,但我没有找到任何可以解决我的问题的相关答案,我HttpURLConnection
用来从 url 获取响应作为 xml,它工作正常但有时我得到这个异常:
java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
,我使用了以下代码,url1 是我的 url,它提供了一个 xml。
url=new URL(url1);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoInput(true);
urlConnection.connect();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String result, line = reader.readLine();
result = line;
while((line=reader.readLine())!=null)
{
result+=line;
}
System.out.println("Result: "+result);