After starting my work with Angular 2 and TypeScript, everything was going great. However, I encountered an issue when working with a REST API (POST) where the console log displayed
Response {_body: "", status: 204, statusText: "Ok", headers: Headers, type: 2… }
. Despite passing the correct parameters for logging in, this is my code:
authentification(){
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
// headers.append('Content-Type', 'application/json');
return this.http.post(this._postUrl,JSON.stringify({username:"abc",password:"abc"}),{headers:headers});
}
And here is my web service:
@POST
@Path("/admin")
@Consumes("application/x-www-form-urlencoded")
public User getDate(@HeaderParam("username")String username,@HeaderParam("password")String password) throws Exception{
try {
String passwordC = AESCrypt.encrypt(password);
User u = userService.login(username, passwordC);
return u;
} catch (Exception e) {
return null;
}
}
It seems like the problem lies in the parameter difference between the string in my web service and JSON in Angular. Can anyone help me with this? Thank you.