Android Volley error.getMessage() is blank

前端 未结 1 343
失恋的感觉
失恋的感觉 2021-01-11 11:05

So I am making a POST JSonObjectRequest to my server and when it is successful everything works and the info is posted, but if there is an error and I try to display it in a

相关标签:
1条回答
  • 2021-01-11 11:38

    The VolleyError object has a networkResponse reference, try to check it to see if you can get some useful information from there.

    @Override
    public void onErrorResponse(VolleyError error) {
        if (error == null || error.networkResponse == null) {
            return;
        }
    
        String body;
        //get status code here
        final String statusCode = String.valueOf(error.networkResponse.statusCode);
        //get response body and parse with appropriate encoding
        try {
            body = new String(error.networkResponse.data,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            // exception
        }
    
        //do stuff with the body...
    }
    
    0 讨论(0)
提交回复
热议问题