Results 1 to 2 of 2
  1. #1
    Alayna is offline Member
    Join Date
    May 2007
    Rep Power

    Default How to make a HTTP connection to a website

    I want to connect to a website from my Java application, download its source and process it. How can i download the source code of a web page?

  2. #2
    levent Guest


    You can use URLConnection class.

    Here is a sample code:

    Java Code:
            try {
                URL google = new URL("");
                URLConnection googleConnection = google.openConnection();
                DataInputStream dis = new DataInputStream(googleConnection.getInputStream());
                String inputLine;
                while ((inputLine = dis.readLine()) != null) {
            } catch (MalformedURLException me) {
                System.out.println("MalformedURLException: " + me);
            } catch (IOException ioe) {
                System.out.println("IOException: " + ioe);
    If you have more advanced requirements, i recommend you to use Apache HTTPClient library.

Similar Threads

  1. Kode Java Website
    By wsaryada in forum Reviews / Advertising
    Replies: 4
    Last Post: 01-18-2008, 10:16 PM
  2. website java button layout
    By abcdefg in forum AWT / Swing
    Replies: 0
    Last Post: 12-25-2007, 05:44 PM
  3. Getting content type from a website
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-26-2007, 02:06 PM
  4. Getting character set from a website
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-26-2007, 01:53 PM
  5. How do i read from a website with a certificate??
    By karl in forum Advanced Java
    Replies: 0
    Last Post: 07-12-2007, 05:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts