aspose file tools*
The moose likes Java in General and the fly likes Getting the contents from the URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting the contents from the URL" Watch "Getting the contents from the URL" New topic
Author

Getting the contents from the URL

hemant Budhewar BamniBk
Ranch Hand

Joined: May 09, 2009
Posts: 33

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
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
hemant Budhewar BamniBk
Ranch Hand

Joined: May 09, 2009
Posts: 33
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
Is the browser possibly configured to go through a proxy?


Ping & DNS - updated with new look and Ping home screen widget
hemant Budhewar BamniBk
Ranch Hand

Joined: May 09, 2009
Posts: 33
Ulf Dittmer wrote:Is the browser possibly configured to go through a proxy?


yes
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
Don't fret; here's how to connect through a proxy.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting the contents from the URL
 
Similar Threads
java.net.ConnectException
Unable to display the UI
java Scanner
XML Parsing error
java.net.UnknownHostException