Hi,
I am trying to use HttpURLConnection to grab a web page. In the
following code, if I change myUrl to "http://www.yahoo.com", the code
runs fine. But with the weather.com url,
urlConnection.getResponseCode() just
hang there forever. If I launch
"http://www.weather.com/outlook/travel/local/94025?" on any browser, it
reaches the website fine. Did anybody has similar experience or any
suggestions? Have I missed anything in the code ?
String myUrl ="http://www.weather.com/outlook/travel/local/" + "94025" + "?"
try{
URL url = new URL(myUrl);
System.out.println("new URL");
urlConnection = (HttpURLConnection)url.openConnection();
System.out.println("openConnection");
httpResponse = urlConnection.getResponseCode();
System.out.println("getResponse");
if (httpResponse != HttpURLConnection.HTTP_OK){
System.out.println("Error connecting to" + myUrl+"
Response Code = "
+ String.valueOf(httpResponse));
}
inStream = urlConnection.getInputStream();
System.out.println("getInputStream");
System.out.println(myUrl);
BufferedReader bReader = new BufferedReader(new
InputStreamReader(inStream));
while ((line = bReader.readLine() ) != null) {
htmlStrBuffer.append(line);
htmlStrBuffer.append('\n');
}
}
catch(Exception e)
{
e.printStackTrace();
}
Thanks in advance,
Jie
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html