От javadoc:
Она возвращает 200 и 401 соответственно. Возвращает -1, если код не может быть распознан из ответа (т. Е. Ответ недействителен HTTP).
Возвращает: HTTP-статус-код, или -1
Броски: IOException - если произошла ошибка подключения к серверу.
Значение, если код еще не известен (еще не запрошен для сервера), соединения открыты и выполнено соединение (на этом этапе может произойти событие IOException).
Если мы посмотрим в исходный код, который мы имеем:
public int getResponseCode() throws IOException {
/*
* We're got the response code already
*/
if (responseCode != -1) {
return responseCode;
}
/*
* Ensure that we have connected to the server. Record
* exception as we need to re-throw it if there isn't
* a status line.
*/
Exception exc = null;
try {
getInputStream();
} catch (Exception e) {
exc = e;
}
/*
* If we can't a status-line then re-throw any exception
* that getInputStream threw.
*/
String statusLine = getHeaderField(0);
if (statusLine == null) {
if (exc != null) {
if (exc instanceof RuntimeException)
throw (RuntimeException)exc;
else
throw (IOException)exc;
}
return -1;
}
...