无法从客户端连接到web服务

tvmytwxo  于 2021-07-09  发布在  Java
关注(0)|答案(2)|浏览(290)

我正在尝试使用webapi
api:-

@CrossOrigin(origins="http://IP:4200")
    @RestController
    @RequestMapping("/api/v1")
    public class BasicAuthController {
            @PostMapping(path = "/authenticate")
            public ResponseEntity<?> createAuthenticationToken(@RequestBody JwtRequest authenticationRequest) {

                log.info("end createAuthenticationToken method");
                return ResponseEntity.ok(userDetailsinfo);
            }
    }

client:-

authenticationService(formData) {
      return this.http.post<any>('/api/v1/authenticate',   formData).pipe(map((res) => {
       debugger;
    }));  
  }

proxy.config.json文件

{
    "/api": {
        "target": "http://IP:8080",
        "secure": false,
        "changeOrigin": true
    }
}


我已经使用 ng-serve

7rfyedvj

7rfyedvj1#

您可以在angular.json文件上配置代理配置。请看下面的示例:

"serve": {

          "options": {
            ...
            "proxyConfig": "proxy.conf.json",
            "aot": true
            ...
          }
}

或者如前所述,您可以用proxy config proxy.conf.json启动应用程序

jmp7cifd

jmp7cifd2#

ng serve --proxy-config proxy.conf.json

尝试使用此命令启动应用程序以使用代理配置。

相关问题