Hi,
I want to get the information from the 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
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
but ,i have an exception
java.lang.ClassCastException: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream cannot be cast to java.lang.String
how can i retrieve data from the website?
If any have the working code pls show me
thank you in advance