0

I am trying to make a GET request using Volley from my android phone to a HTTP server written on Spring.

I've made a custom request that extends Request and override its getParams() metod:

@Override
protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> parameters = new HashMap<>();
        parameters.put("email", "xxxx@xxx.com");
        parameters.put("password", "xxxx");    
        return parameters;
}

I am making my request in the this way:

GsonRequest = new GsonRequest<String>(Request.Method.GET, "http://192.168.43.15:10000/login",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        ....
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ......
                    }
        });
Log.i(TAG, new String(request.getBody()));
requestQueue.add(request);

Log shows that the request is having this params:

email=xxxx%40xxx.com&password=xxxx&

But there is an error:

Unexpected response code 400 for http://192.168.43.15:10000/login

It looks like the request parameters are not sent.


This is my server code:

@RequestMapping(path = "/login", method = RequestMethod.GET)
public ResponseEntity<String> login(@RequestParam(name = "email") String email,
                                    @RequestParam(name = "password") String password) {
  User user = repository.findByEmailAndPassword(email, password);
    if (user != null) {
        return new ResponseEntity("Found", HttpStatus.OK);
    }

    return new ResponseEntity<>("Not found", HttpStatus.OK);
}

I think that something is wrong with the code on my android device because when I make the request from the browser everything is OK.

Can someone tell me where the problem is?

user3577832
  • 23
  • 1
  • 6
  • May you can use **StringRequest** instead of **JSONRequest** because you are returning a string response. – Frank Jun 18 '17 at 09:43
  • It look like you want to send some data to the server but you using GET method for that, Try it with POST method,the error come when database don't receive the parameter that are compulsory. – Ajeet Choudhary Jun 18 '17 at 09:50

1 Answers1

0

After some looking I found this post where is explained why the params are not sent.

Volley - how to send DELETE request parameters?

user3577832
  • 23
  • 1
  • 6