'request.getParameter return null
I work on spring boot and angular I made an authentication based on spring security I tested with postman and everything works fine, but when I use angular it does not work after debugging I noticed that request. getParameter("username") return null, the error is probably on the angular request, please can someone help me
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
// TODO Auto-generated method stub
String username = request.getParameter("username");
System.out.println(username);
String password = request.getParameter("password");
System.out.println(password);
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(username, password);
return authManager.authenticate(authToken);
}
//req angular
login(params:any) : Observable<any> {
let username=params.username as string
let password=params.password as string
const FORM_URL = {
headers:{
'Content-Type': 'application/json'
}
}
return this.http.post<any>(`${this.adresse+'/login'}`,{
'username':username,
'password':password
}, FORM_URL)}
}
Solution 1:[1]
According to the documentation: Returns the value of a request parameter as a String, or null if the parameter does not exist.
Find out where this parameter should come from. Candidates are the client request, the container and the Sprint Boot framework. Once you know which side is supposed to set it, figure out why it does not.
One answer can be as simple as 'the user has not yet authenticated'. For a more focused response you'd have to share more details.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hiran Chaudhuri |
