我有一個是通過使用凌空給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