My Android Volley JsonObjectRequest runs into onErrorResponse with the issue:
我的Android Volley JsonObjectRequest遇到问题时遇到onErrorResponse:
BasicNetwork.performRequest: Unexpected response code 405 for MY_URL
My URL is valid. I have checked that with a browser and I get there the expected JSON Object. So the issue has to be on the client side.
我的网址有效。我用浏览器检查了一下,然后我就到达了预期的JSON对象。所以问题必须在客户端。
The code 405 means:
代码405表示:
Method Not Allowed The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.
方法不允许请求行中指定的方法不允许由Request-URI标识的资源。响应必须包含一个Allow标头,其中包含所请求资源的有效方法列表。
my code for JsonObjectRequest:
我的JsonObjectRequest代码:
JsonObjectRequest jsonReq;
jsonReq = new JsonObjectRequest(URL_FEED, new JSONObject(),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
VolleyLog.v("Response:%n %s", response.toString(4));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.v("ERROR:%n %s", error.getMessage());
}
});
// Adding request to volley request queue
NetworkController.getInstance().addToRequestQueue(jsonReq);
Do I have to add some information to the header? And if what for information?
我是否必须在标题中添加一些信息?如果有什么信息?
2 个解决方案
#1
7
The issue was that the request was set to POST
by default. The solution that worked for me:
问题是默认情况下请求设置为POST。对我有用的解决方案:
JsonObjectRequest jsonReq = new JsonObjectRequest
(Request.Method.GET, URL_FEED, null, new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
Log.d("Server", "Läuft");
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Log.d("Server","onErrorResponse");
}
});
NetworkController.getInstance().addToRequestQueue(jsonReq);
#2
0
Use GET Method instead of POST it has worked for me.
使用GET方法而不是POST它对我有用。
#1
7
The issue was that the request was set to POST
by default. The solution that worked for me:
问题是默认情况下请求设置为POST。对我有用的解决方案:
JsonObjectRequest jsonReq = new JsonObjectRequest
(Request.Method.GET, URL_FEED, null, new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
Log.d("Server", "Läuft");
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Log.d("Server","onErrorResponse");
}
});
NetworkController.getInstance().addToRequestQueue(jsonReq);
#2
0
Use GET Method instead of POST it has worked for me.
使用GET方法而不是POST它对我有用。