wood burning stoves 2.0*
The moose likes Java in General and the fly likes HttpURLConnection 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 "HttpURLConnection" Watch "HttpURLConnection" New topic


Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150

I want to read content of the web site through java program. I am using HttpURLConnection class. But I am unable to view the contents. I got code from net "Html source viewer". But what if website is in php, jsp etc.
Any pointers ??


~ Anand,
SCJP 1.5
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39576
Reading the content of a web page could be as simple as:

It doesn't matter whether the web site is written in JSP, PHP or Fortran, because either way you're going to get HTML delivered back to you.
[ March 22, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hi Ulf,

Solution given by you is not working. See the stack trace below :
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913)
at java.net.URLConnection.getContent(URLConnection.java:682)
at java.net.URL.getContent(URL.java:1021)
at Tp.main(Tp.java:20)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884

Are you behind a proxy?

Connect through a Proxy
Java Tip 42: Write Java apps that work with proxy-based firewalls

The official documentation: Networking Properties

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Thanks a lot, Jesper.
I agree. Here's the link: http://aspose.com/file-tools
subject: HttpURLConnection
Similar Threads
EOF error
Polling from java Web start to web server
How to get a String from an InputStream
java.io.IOException: Premature EOF
HttpURLConnection - getting the response content