Search code examples
javaandroidhttpurlconnectionhttp-response-codes

How can I get the description of ResponseCode of HttpURLConnection?


After calling the following code, getResponseCode() returns the response code returned by the remote HTTP server. This code has a short description. How can I get its description programmatically in Android?

URL myurl = new URL(url);
URLConnection connection = myurl.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();

UPDATE

httpConnection.getResponseMessage() sometimes returns "not found" whereas responseCode is valid


Solution

  • try getResponseMessage(), it will a string message you may interesting.