facebook

retrieve data from a website using HttpURLConnection

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #291459 Reply

    Pradeep_J
    Member

    Hi ,
    My aim is to retrieve data from a website using HttpURLConnection
    I wrote this

    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;

    public class webPractice
    {

    public static void main(String[] args)
    {

    try
    {
    URL yahoo = new URL(“http://www.yahoo.com/”);
    URLConnection yahooConnection = (URLConnection) yahoo.openConnection();
    yahooConnection.connect();
    long s=yahooConnection.getDate();

    System.out.println(“date”+(String)yahooConnection.getContent());
    System.out.println(“Hi”);
    }
    catch (MalformedURLException e)

    {
    System.out.println(“URL Exception”);
    // new URL() failed
    }
    catch (IOException es)
    {
    System.out.println(“IO Exception”);
    es.printStackTrace();
    // openConnection() failed
    }

    }

    }

    It is giving the exception as

    java.net.UnknownHostException: http://www.yahoo.com
    IO Exception
    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 webPractice.main(webPractice.java:19)

    How can I retrieve the data from a website?
    If do u have any working code plz show me….

    #291489 Reply

    Loyal Water
    Member
Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: retrieve data from a website using HttpURLConnection

You must be logged in to post in the forum log in