I've tried to download HTML content from the URL http://google.com
and another URL.
I tried:
URL url = new URL("http://google.com/");
urlConnection = (HttpURLConnection) url.openConnection();
And although I've tried InputStream
, it didn't work the same.
try {
URL url = new URL("http://google.com/");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
System.out.print(urlConnection.getResponseCode());
}
catch (Exception e)
{
System.out.print("Error: "+e.getMessage());
}
finally {
urlConnection.disconnect();
}
At the end I see the catch
and the e.getMessage
is null
. If I debug it, urlConnection.getResponseCode()
is returning -1
.