[Logo]
Forums Register Login
Getting the contents from the URL

I have been using URL and URLConnetion api's, but getting problem saying,


Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.MaiYUYTY.main(Maina.java:34)

Can anybody having idea about the resoulution
You can't connect to the port on the host you specified, and after a timeout it simply fails. Are you sure you can reach the URL? You can try with a regular browser like Internet Explorer or Firefox.
 

Rob Prime wrote:You can't connect to the port on the host you specified, and after a timeout it simply fails. Are you sure you can reach the URL? You can try with a regular browser like Internet Explorer or Firefox.



Thruogh the browser I can get the page but with code I even not get connected to that URL.

Please let me know if you need any more information.

Thanks
Is the browser possibly configured to go through a proxy?
 

Ulf Dittmer wrote:Is the browser possibly configured to go through a proxy?



yes
Don't fret; here's how to connect through a proxy.
 

Ulf Dittmer wrote:Don't fret; here's how to connect through a proxy.


That link is obviously a bit older, since it is missing one option introduced in Java 5.0: use java.net.Proxy. URL has overloaded the openConnection method to take a Proxy object as well.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards


This thread has been viewed 1129 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jan 20, 2018 20:14:31.