1

I am trying to register some data with an api and I have checked the json that I get in my application and the structure and data are fine, I put it in Postman and it works fine, the url is also fine, someone could help me to know what I am doing wrong ?

this is the method with which I try to make the call to the api

private void request2(final String json){
    // Instantiate the RequestQueue.
    RequestQueue mRequestQueue = SingletonRequestQueue.getInstance(getApplicationContext()).getRequestQueue();

    // Request a string response from the provided URL.
    StringRequest stringRequestPOSTJSON = new StringRequest(Request.Method.POST, BASE_URL + "/api/Asociado/RegistrarAsociado", new Response.Listener() {
        @Override
        public void onResponse(Object response) {
            // response..
        }

    }, errorListener) {
        @Override
        public Priority getPriority() {
            return Priority.HIGH;
        }

        @Override
        public Map getHeaders() throws AuthFailureError {
            HashMap headers = new HashMap();
            headers.put("Authorization", "Bearer "+ bearertoken);
            return headers;
        }
        @Override
        public byte[] getBody() throws AuthFailureError {
            String your_string_json = json; // put your json
            return your_string_json.getBytes();
        }

    };
    // Add the request to the RequestQueue.
    mRequestQueue.add(stringRequestPOSTJSON);
}

This is the error I get: E/Volley: [4146] BasicNetwork.performRequest: Unexpected response code 400 for

Nick
  • 138,499
  • 22
  • 57
  • 95

1 Answers1

1

try this code:

  stringRequest.setRetryPolicy(new DefaultRetryPolicy(
                30000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));