拒绝设置不安全的标头“主机”

时间:2018-08-22 11:27:39

标签: angular http asp.net-core cors http-headers

我正在使用.NET Core开发Angular 5应用程序,并且确实需要将Host作为标头发送,因为我正在使用TRAEFIK来处理请求。

这里是我的角度代码:

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
      request = request.clone({
          withCredentials: true,
          setHeaders: {
            Authorization: `Bearer ${this.apiService.kcs.client().token}`,
            Host: 'servercore.docker.localhost'
          }
        });
    return next.handle(request);
  }

在Startup.cs的API中,我有以下代码

////public void ConfigureServices(IServiceCollection services)
services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                    builder => builder
                    .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
            });

////public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
app.UseCors("CorsPolicy");

问题在于,当我发送请求时,它会引发此错误:

  

拒绝设置不安全的标头“主机”

     

无法加载http://xxx.xxx.xxx.xxx/api/graphql/graph/:对预检请求的响应未通过访问控制检查:所请求的资源上没有'Access-Control-Allow-Origin'标头。因此,不允许访问来源“ http://localhost:4200”。

     

跨域读取阻止(CORB)阻止了MIME类型为text / plain的跨域响应http://xxx.xxx.xxx.xxx/api/graphql/graph/。有关更多详细信息,请参见https://www.chromestatus.com/feature/5629709824032768

有人可以告诉我为什么会这样,因为在我的API中有AllowAnyOriginAllowAnyHeader。另外,我认为如果我处理该Host标头,则原点将允许它。

0 个答案:

没有答案