'Android HttpsURLConnection: getErrorStream works but not getInputStream

I want to get a json string from my remote server.

I have a very weird problem as I manage to get my json string only thanks to getErrorStream but not thanks to getInputStream.

Here is my code:

URL url = new URL("my_https_url");

HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
          
connection.connect();

int responseStatusCode = connection.getResponseCode(); // ERROR 500 HERE

InputStream inputStream;

if(responseStatusCode != HttpsURLConnection.HTTP_OK ) {

inputStream = connection.getErrorStream(); // I pass through here

} else {

inputStream = connection.getInputStream();

}

response = IoUtils.readAll(inputStream); // I get my json string properly after being passed through getErrorStream()

If I remove my 'if statement' and try to do only:

inputStream = connection.getInputStream()

I get a fileNotFoundException.

Anybody has a clue how to solve this issue?

Thanks.



Solution 1:[1]

Adding this to your .box would get the text to the bottom aligned with the icon.

.box {
  display: flex;
  flex-direction: row-reverse;
}

Changing .grid-overlay padding to remove to top would make it look like this:

screen shot

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1