- This topic has 1 reply, 2 voices, and was last updated 16 years ago by Loyal Water.
-
AuthorPosts
-
Pradeep_JMemberHi ,
My aim is to retrieve data from a website using HttpURLConnection
I wrote thisimport 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….
Loyal WaterMemberPlease don’t cross post the same query:-
https://www.genuitec.com/forums/topic/error-while-fetching-data-from-a-website/ -
AuthorPosts