Android Volley: 405 unexpected response code

My Android JsonObjectRequest drive is starting on onErrorResponse with a problem:

BasicNetwork.performRequest: Unexpected response code 405 for MY_URL

My url is valid. I checked this with a browser and I get the expected JSON object. Therefore, the problem should be on the client side.

Code 405 means:

Method not allowed. The method specified in the query string 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.

my code for 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 need to add some information to the header? And if for information?

+4
source share
1 answer

, 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);
+6

Source: https://habr.com/ru/post/1615391/


All Articles