Charles Galvez
Charles Galvez

Reputation: 1110

String Request BasicNetwork.performRequest: Unexpected response code 401

My partner made an API.
Then in the given link I'm trying to get the datas in JSON.
In postman it's working fine.
And in postman i just set the Authorization to No Auth and paste the link and its working.
In android its different.
I am receiving Error code 400. But when i tried it in android studio it's not working.

 String REVIEW_URL;
    REVIEW_URL ="http://be0658e94af429e2150dd0a3dc1a199a:[email protected]/api.php/reviews/12";
    RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
    StringRequest request = new StringRequest(Request.Method.GET, REVIEW_URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.e("RESPONSE:", response);
            Toast.makeText(SignUp.this, response, Toast.LENGTH_SHORT).show();
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            return params;
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> header = new HashMap<>();
            return header;
        }

    };
    requestQueue.add(request);

I am receiving this error.

01-09 01:19:24.828 9109-9210/com.toweelo E/Volley: [245] BasicNetwork.performRequest: Unexpected response code 401 for http://be0658e94af429e2150dd0a3dc1a199a:[email protected]/api.php/reviews/12

Upvotes: 0

Views: 1077

Answers (1)

Jorgesys
Jorgesys

Reputation: 126493

Since you are using the GET method, check if REVIEW_URL value is really correct,

A 400 error means that the request was malformed. In other words, the data stream sent by the client to the server didn't follow the rules.

Upvotes: 0

Related Questions