Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpURLConnection reading response content on 403 error [duplicate]

When I fetch data from an URL with a 403 response

is = conn.getInputStream(); 

It throws an IOException and I can't get the response data.

But when I use firefox and access that url directly, The ResponseCode is still 403, but I can get the html content

like image 214
yava Avatar asked Jan 08 '11 08:01

yava


1 Answers

The HttpURLConnection.getErrorStream method will return an InputStream which can be used to retrieve data from error conditions (such as a 404), according to the javadocs.

like image 179
coobird Avatar answered Oct 01 '22 03:10

coobird