标签云

微信群

扫码加入我们

WeChat QR Code

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.


What happens when you send request from angular? What error it shows?

2018年08月18日35分13秒

if any ans is helpful the plz try to do upvote and if answer is right then mark as accepted coz other dev can see that ans first.

2018年08月18日35分13秒