I'm retrieving the content of a invalid web address with volley, i.e. http://www.gigd32fdsu.com
:
This is my test code:
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
final String url = "http://www.gigd32fdsu.com";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener() {
@Override
public void onResponse(Object response) {
// Display the first 500 characters of the response string.
mTextView.setText("Response is: " + response.toString().substring(0, 500));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTextView.setText("That didn't work! " + error.networkResponse.statusCode);
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
When I run this code I receive the callback onResponse(String) with an error page from my ISP. How can I read the HTTP status code in order to detect that the web displaying is not correct?
Thanks