Android Volley:意外的响应代码405

前端之家收集整理的这篇文章主要介绍了Android Volley:意外的响应代码405前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的 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);

猜你在找的Android相关文章