Reputation: 43
I am able to successfully send a post request to my restcontroller in spring boot using postman.
The restcontroller is as follows:
@RequestMapping(value="/performaction",method=RequestMethod.POST,consumes = "application/json", produces = "application/json")
public void performReboot(@RequestBody PerformAction performAction) {
System.out.println("......rebooting blade to performRebootservice...........for blade id :: : ::"+performAction.getBladeId() +performAction.getActionName());
..........
}
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*");
}
};
}
However I am not able to send this post request from my angular, the request is as follows:
const headers = new HttpHeaders().set("Content-Type", "application/json");
return this.http.post(this.performactionUrl, {"bladeId" : 2,"actionName" : "reboot"},{headers});
Note: I have added the WebMvcConfigurer from here!
Thanks.
Upvotes: 1
Views: 1291
Reputation: 86730
return this.http.post(this.performactionUrl, {"bladeId" : 2,"actionName" : "reboot"},{headers});
should be -
return this.http.post(this.performactionUrl, JSON.stringify({"bladeId" : 2,"actionName" : "reboot"}),headers);
Upvotes: 0
Reputation: 2582
Without using subscribe
method your api is never called. Just use subscription method in your component.
Upvotes: 3