I want to develop a simple class that can fetch the HTML contents of a URL without using java.net.Url or java.net.UrlConnection classes. Any good suggestions in this regard will be highly appreciated... Thanks in advance...
salman khalid wrote:I want to develop a simple class that can fetch the HTML contents of a URL without using java.net.Url or java.net.UrlConnection classes.
Anyway the way to do that would be to write code which does this:
Extracts the name of the host from the URL
Extracts the port from the URL
Connects to that host on that port using a Socket
Using the HTTP protocol, sends a GET request to the host
Receives the response from the host and interprets it according to the HTTP protocol
You may find your requirement for "a simple class" conflicts with what actually has to be done. That's why I asked why you want to do this.
thanks for the response...I agree with you that it will not be a simple class. I have implemented your suggested method. The following code snippet describes this method, but there is a problem in this approach and that is that it does not retrieve HTML contents when a URL contains the file path as well.
like "www.google.com" URL will return HTML contents but not "http://www.oracle.com/technetwork/java/index.html" URL.