How to Get the Response Code Returned by a Remote HTTP server

public int getResponseCode () was added in API level 1
Returns the response code returned by the remote HTTP server.
Returns: the response code, -1 if no valid response code.
Throws: IOException - if there is an IO error during the retrieval.

1. Get a new HttpURLConnection

2. Create an Integer Variable named responseCode




4. Add the below line in the try/catch right after you get a new HttpURLConnection above(in step #1). This must be in the try/catch statement.

responseCode = myHttpURLConnection.getResponseCode();

5. Compile and run! 

Next Recommended Article: How to Check if Response Code is OK