httpurlconnection on android:

Asked

Viewed 40 times

0

Hello, I’m trying to get the http response code, and I’m using this code :

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

int code = connection.getResponseCode();

The problem is the following : getResponseCode(); get the code once ? , or by calling it it will update the status with the current code?

1 answer

2


Each time you call it will return the status code:

 HTTP/1.0 200 OK
 HTTP/1.0 401 Unauthorized

Or if it is not a valid HTTP response it will return -1.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.