我有一个是通过使用凌空给200响应代码邮差但不调用API时POST方法API甚至Retrofit2。获得响应代码200邮递员,但不是在Android网络图书馆
这里是邮差截图:
这里我就是这样做的凌空库代码:
final String url = "http://xxxxxxxx.com/api/mobile/user/post/";
StringRequest stringReq = new StringRequest(Request.Method.POST, url,
new com.android.volley.Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("onResponse ===", response + " ");
}
},
new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("onErrorResponse ===", error + " ");
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Authorization", "xxxxxxxxxxxxx");
return params;
}
@Override
public Map<String, String> getParams() {
HashMap<String, String> params = new HashMap<>();
params.put("post_body", "test");
return params;
}
};
// Adding request to request queue
mApp.addToRequestQueue(stringReq);
stringReq.setRetryPolicy(new DefaultRetryPolicy(
REQUEST_TIME,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
错误logcat的:
BasicNetwork.performRequest: Unexpected response code 500 for http://xxxxxxxxxxx.com/api/mobile/user/post/
能否请您分享您的清单? 您是否添加了以下权限? “android.permission.INTERNET” “android.permission.ACCESS_NETWORK_STATE” –
你这个男人毫不怀疑。 –
500是服务器错误。我对这些情况的体验通常与头文件有关。邮差默认添加了一些翻新和排除的标题。有时候服务器无法应对这种缺少头部并投掷500。我建议你检查一下。这可能是另一种方式。 – Fred