I am working on a login system - and was using previously get methods. When I run the application the ajax request seems correct - but the server side parameters coming in are null?
old code...
-- server side
@SuppressWarnings("unchecked")
@RequestMapping(value = "/login", method = RequestMethod.GET)
@CrossOrigin(origins = {"*"})
public ResponseEntity<?> login(
@RequestParam(value="email", required=false, defaultValue="email") String email,
@RequestParam(value="password", required=false, defaultValue="password") String password,
HttpServletRequest request
) throws Exception {
-- front side
export function fetchAuthentication(data) {
let url = 'http://localhost:8080/login?email=ruperttest2@hotmail.com&password=1234';
return function (dispatch) {
axios.get(url)
.then(function (response) {
dispatch(authSuccess(response));
})
.catch(function (error) {
dispatch(authFail(error));
});
}
}
new code..
-- server side
@SuppressWarnings("unchecked")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@CrossOrigin(origins = {"*"})
public ResponseEntity<?> login(
@PathVariable(value="email", required=false) String email,
@PathVariable(value="password", required=false) String password,
HttpServletRequest request
) throws Exception {
System.out.println("email email>>>"+email);
-- front side
export function fetchAuthentication(data) {
let url = 'http://localhost:8080/login';
return function (dispatch) {
axios.post(url, data)
.then(function (response) {
if(response.status === "success"){
dispatch(authSuccess(response));
}
else{
// fail - user not found for example
dispatch(authFail(response));
}
})
.catch(function (error) {
dispatch(authFail(error));
});
}
}