我的
Android Volley JsonObjectRequest遇到问题时遇到onErrorResponse:
BasicNetwork.performRequest: Unexpected response code 405 for MY_URL
我的网址有效.我用浏览器检查了一下
我到达那里预期的JSON对象.
所以问题必须在客户端.
代码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.
我的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);
解决方法
问题是默认情况下请求设置为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);