I am trying to execute a post call from an angular application to an api developed with Spring boot. What happens is that I do not bind between the object I sent and the one that is expected as a parameter. If I run it from postman sending the parameters as form-data or urlencoded works fine, but not from the application.
My code is as follows:
UserById(param: Object): any {
console.log(JSON.stringify(param));
return this._http.post('http://localhost:8080/user/userbyid', JSON.stringify(param), this.opciones()).pipe(
map((res: Response) => {
return res.json();
}),
);
}
Try to send the object as JSON as seen in the coffin and without pairing and in neither of the two ways it works. An example of JSON that I send is:
{"User":"leonardo_alvarez","User2":"Usuario2"}
The API code is the following:
public class userObj {
private String user;
private String user2;
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getUser2() {
return user2;
}
public void setUser2(String user2) {
this.user2 = user2;
}
}
@Autowired
private REL_UserRepository rel_userRepository;
@PostMapping(path = "/userbyid")
public @ResponseBody List<REL_User> getUser (userObj User){
return rel_userRepository.findByUserid(User.getUser());
}
Does anyone know that this may be happening?