【问题标题】:Not able to connect to web service from angular client无法从 Angular 客户端连接到 Web 服务
【发布时间】:2020-08-20 05:44:18
【问题描述】:

我正在尝试使用 web api

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);
            }
    }

客户:-

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 运行客户端应用程序

【问题讨论】:

    标签: java angular spring spring-boot


    【解决方案1】:
    ng serve --proxy-config proxy.conf.json
    

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

    【讨论】:

      【解决方案2】:

      您可以在 angular.json 文件中配置代理配置。部分服务看看这个例子:

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

      或者如前所述,您可以使用 --proxy-config proxy.conf.json 启动您的应用

      【讨论】:

        猜你喜欢
        • 2013-02-22
        • 1970-01-01
        • 2012-10-15
        • 1970-01-01
        • 2010-11-17
        • 2020-07-20
        • 1970-01-01
        相关资源
        最近更新 更多