So this is a beginner question.
When executing the example code from working with URLs , it throws:
Exception in thread "main" java.net.SocketException: Connection reset on java.net.SocketInputStream.read (SocketInputStream.java:189) ...
Origin is the openStream () method.
Here is the code:
import java.net.*; import java.io.*; public class URLReader { public static void main(String[] args) throws Exception { URL oracle = new URL("http://www.oracle.com/"); BufferedReader in = new BufferedReader( new InputStreamReader(oracle.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } in.close(); } }
I know that there are similar topics for this topic, but I could not find an answer that suits me.
What I have tried so far :
- I set the proxy host as suggested here . The command was: java -Dhttp.proxyHost = dslb-088-071-100-199.pools.arcor-ip.net, I also tried it with the insert System.setProperty ("http.proxyHost", "dslb-088-071- 100-199.pools.arcor-ip.net "); in the first line of the URLReader class.
- I tried JSoup html parser and
- org.apache.commons.io.FileUtils.copyURLToFile (URL, File) to have a similar result.
No matter what I try, I always get the same error: nothing will happen for 30 seconds or so, and then it throws the specified SocketException.
I just donβt know how to continue solving this problem. It would be useful to get information about what happens in the background for 30 seconds before the reset connection.
So what can actually cause this exception?
The smallest hint can help! Thanks!
source share