我正在尝试将齐射请求解析为“JsonObjectRequest”,
我收到的错误为“com.android.volley.ServerError”,不知道原因是什么。
RequestQueue queue = Volley.newRequestQueue(mConetxt);
JsonObjectRequest putRequestUNregister = new JsonObjectRequest(Request.Method.POST, Global.un_register_device, deviceInfoUnRegister,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response) {
// response
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// error
hideProgress();
notificationInterface.NotificationReturn(false);
Log.e("Error.Response","notify onErrorResponse VolleyError "+ error.toString());
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
Log.e("Error.Response","notify onErrorResponse VolleyError TimeoutError"+ error.toString());
} else if (error instanceof AuthFailureError) {
Log.e("Error.Response","notify onErrorResponse VolleyError AuthFailureError"+ error.toString());
} else if (error instanceof ServerError) {
Log.e("Error.Response","notify onErrorResponse VolleyError ServerError"+ error.toString());
//TODO
} else if (error instanceof NetworkError) {
Log.e("Error.Response","notify onErrorResponse VolleyError NetworkError"+ error.toString());
//TODO
} else if (error instanceof ParseError) {
Log.e("Error.Response","notify onErrorResponse VolleyError ParseError"+ error.toString());
//TODO
}
}
}
) {
@Override
public Map<String, String> getHeaders()
{
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
headers.put("Accept", "application/json");
return headers;
}
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
@Override
public byte[] getBody() {
try {
return deviceInfoUnRegister.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
};
这就是我试图解析的方式, 并收到错误“ VolleyError com.android.volley.ServerError”
将代码替换为
headers.put("Content-Type", "application/json; charset=utf-8");
headers.put("Accept", "application/json");
到
headers.put("Accept","application/json");
headers.put("Content-Type","application/json");
headers.put("Content-Type", "application/json; charset=utf-8"); headers.put("接受", "application/json");***