Question:

Using sockets (to connect to a website) with Java

by  |  earlier

0 LIKES UnLike

Is it possible to use sockets with the Java programming language in order to access information from websites? Its very easy to do using a program called mIRC, but I haven't used Java for it yet.

If it is possible, can someone provide me an example?

 Tags:

   Report

1 ANSWERS


  1. Yes, you can do it using java socket programming. Most URLs of the websites are accessed through http protocol by simply opening a connection on port 80 to the webserver that hosts the pages and specifying the URL of the webpage that you are trying to access.

    In complex business/banking situations https protocol is used for which there is a separate authentication method before you can access the webpage information. These pages are in encrypted form and cannot be decrypted easily unless you are the right user. The https protocol listens on port 443.

    Here is a java resource that reads the webpage for the specified url from a http based webserver.

    Remember, this will actually display the html text data of the webpage (The one you see in Notepad when you right click on a webpage and click "View Source") that is used to render the page in a browser. Finally, it is the browser like IE/Mozilla which has capability to display the webpage.

    If you know unix text processing utilities like grep,sed,awk you can do a lot with this text data to parse the output as per your requirement or simply try to utilize the built-in APIs for java like StringTokenizer that possess strong text parsing capabilities.

    Good Luck!  

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.