I have a weird situation that may be because I missed something that I didn't realized or know. I am creating a simple login UI using Angular and call the Web API created in Java.
The Java web API function is as follows:
@RequestMapping(value = "/logon", method = RequestMethod.POST, produces = {"application/json"})
@ResponseBody
public String logon(
@RequestParam(value = "userID", required = true) String userID,
@RequestParam(value = "password", required = true) String password,
HttpServletRequest request)
Now if I use the http.post as follows:
login(username: string, password: string) {
return this.http.post(this.url+"/security/logon/",
JSON.stringify({ userID: username, password: password }) )
Then I get the following error in the Google Chrome browser:
POST http://localhost:8080/logon/ 400 (Required String parameter 'userID' is not present)
But if I change the code as follows:
login(username: string, password: string) {
var usrpwd = "userID=" + username + "&password=" + password;
return this.http.post(this.url+"/security/logon?"+usrpwd, usrpwd )
It work perfectly.
Am I missing something? Why the second parameter of http.post that should be the parameter passed not seems to be working?