我可以使用php引发带有消息的服务器错误吗?

编程入门 行业动态 更新时间:2024-10-26 08:30:53
本文介绍了我可以使用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引发带有消息的服务器错误吗?

本文发布于:2023-08-07 13:41:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319360.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   错误   消息   服务器   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!