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