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?