Check the response:
InputStream is = connection.getInputStream(); if (connection.getResponseCode()==HttpURLConnection.HTTP_OK) { String contentType = connection.getContentType(); if (contentType.equals("text/xml")) { // Now you can parse your XML response! } }