我正在使用Volley库从Android Java发送一个http请求到ac#backend.后端应用程序响应错误代码和描述,以及StatusDescription.我可以通过wireshark看到响应状态描述,但不知道如何在android端获取描述字符串.
final JsonObjectRequest request = new JsonObjectRequest(JsonObjectRequest.Method.POST,
url,json,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
TextView mTextView = (TextView) findViewById(R.id.output);
print("Success");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
TextView mTextView = (TextView) findViewById(R.id.output);
print("Failure (" + error.networkResponse.statusCode + ")");
//Trying to get the error description/response phrase here
}
}
);
Run Code Online (Sandbox Code Playgroud)
这是处理请求的C#代码:
[WebInvoke(Method ="POST",UriTemplate ="users",BodyStyle = WebMessageBodyStyle.Wrapped,RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)] [OperationContract] void addUser(String username,String firstname,String lastname,String email,String hash){Console.WriteLine(DateTime.Now +"Packet receieved");
//Stores the response …Run Code Online (Sandbox Code Playgroud)