我想使用 volley 库在 android 中使用 json 对象请求发出 PATCH 请求。 它在 postman 中工作,但是当我在 android 中调用它时,它给我错误 405,有人知道如何做吗?下面是我的代码:
requestQueue.add( new JsonObjectRequest(Request.Method.PATCH,url, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
GiveCentralUtilities.setCurrentFragment(getActivity(),R.id.fragment_container,
SignUpPaymentInfo.newInstance(isSignup),SignUpPaymentInfo.TAG);
// getAccessToken();
}
}, this){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> header = new HashMap<String, String>();
header.put("Authorization","Bearer "+GiveCentralUtilities.getPref(GiveCentralConstants.ACCESSTOKEN,getActivity()));
header.put("Accept", "application/json");
// header.put("Content-Type", "application/json");
System.out.println("vivekaccess"+GiveCentralUtilities.getPref(GiveCentralConstants.ACCESSTOKEN,getActivity()));
return header;
}
@Override
public String getBodyContentType() {
return "application/json";
}
});
最佳答案
错误 405 意味着此错误不是来自您的 JsonObjectRequest。这可能是由 url、您的 Android 手机的网络或服务器引起的
关于java - 如何在android volley中使用jSONObjectRequest发出PATCH请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37046861/