本文介绍了我可以使用php引发带有消息的服务器错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在服务器上抛出了一个错误.
I throw a error at server.
header('HTTP/1.1 500 Internal Server Error'); echo 'this is error message'; exit();在客户端,我使用android的Volley发送请求并处理onErrorResponse
At the client side, I use android's Volley to send the request and handle the error in onErrorResponse
new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(getApplicationContext(),error.getMessage(),Toast.LENGTH_LONG).show(); } }但是我在error变量中找不到任何消息,如何向有错误的客户端发送消息?
But I cannot found any message inside the error variable, how can I send a message to client with error?
推荐答案IMO,您可以尝试使用以下方法解析错误消息:
IMO, you can try parse error message if available by using the following:
@Override protected VolleyError parseNetworkError(VolleyError volleyError) { String json; if (volleyErrorworkResponse != null && volleyErrorworkResponse.data != null) { try { json = new String(volleyErrorworkResponse.data, HttpHeaderParser.parseCharset(volleyErrorworkResponse.headers)); } catch (UnsupportedEncodingException e) { return new VolleyError(e.getMessage()); } return new VolleyError(json); } return volleyError; }希望有帮助!
更多推荐
我可以使用php引发带有消息的服务器错误吗?
发布评论