you can cast the returned value of openConnection
to HttpURLConnection
, and use getResponseCode()
to retrieve response code
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
final int responseCode = urlConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
} else if (responseCode == HttpURLConnection.HTTP_BAD_GATEWAY) {
}
HttpURLConnection.getResponseCode()
documentation is here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…