This question already has an answer here:
- Read error response body in Java 6 answers
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
Usage example of
HttpURLConnection
:The
HttpURLConnection.getErrorStream
method will return anInputStream
which can be used to retrieve data from error conditions (such as a 404), according to the javadocs.try this:
source https://stackoverflow.com/a/30712213/505623
try something like this:
I got the same error even after adding agent string. Finally after a days investigation figured out the issue. It is really weired if the url scheme start with "HTTPS" it results in error 403. It should be in lowercase ("https"). So make sure you call "url.toLowercase()" before opening the connection