获取使用 Volley 成功请求的 HTTP 状态代码
2022-09-01 18:51:23
我正在用凌空抽射检索无效网址的内容,即:这是我的测试代码:http://www.gigd32fdsu.com
// 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);
当我运行此代码时,我收到来自ISP的Response(String)上的回调,其中包含错误页面。如何读取 HTTP 状态代码以检测网页显示不正确?
谢谢