1

I am able to successfully send a post request to my restcontroller in spring boot using postman. enter image description here

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.

2 Answers2

3

Without using subscribe method your api is never called. Just use subscription method in your component.

baj9032
  • 2,414
  • 3
  • 22
  • 40
0
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);
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215