简体   繁体   English

我的标题为http post错误中的空角度6

[英]my header is null angular 6 in http post Error

Hello I am using Angular 6 and I am trying to a http post. 您好,我正在使用Angular 6,并且正在尝试发表http帖子。

I know the user is allowing Multiple origins with the 我知道用户允许使用多个来源

    <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*"/> </customHeaders>

my code: 我的代码:

     let data = this.http.post(
            this.base_url + this.walletControllerSubUrl +"login", 
           {username: "exampleuser", password: "Pass123!"}
          );
          data.subscribe(data => console.log(data));
            console.log("data" + data);
            return data;

I always get the error: 我总是得到错误:

" Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values ' http://localhost:8100 , *', but only one is allowed" “对预检请求的响应未通过访问控制检查:'Access-Control-Allow-Origin'标头包含多个值' http:// localhost:8100 ,*',但仅允许一个”

but I also now noticed that my header seems to go null 但我现在也注意到我的标题似乎为空

    headers: Object { normalizedNames: Map(0), lazyUpdate: null, headers: Map(0) }

what would cause the header to be null when I not even passing any header? 当我什至不传递任何标题时,会导致标题为空的原因是什么?

There is another application but in AngularJS, running well with the same post. 但是在AngularJS中还有另一个应用程序,可以在同一篇文章中很好地运行。

what would cause this? 是什么原因造成的?

最近我有同样的错误,只需添加proxy.json文件,其中包含定义服务器真实代理的json并将其添加到启动脚本

Modern browsers using CORS will attempt to send a pre-flight request, usually an OPTIONS call. 使用CORS的现代浏览器将尝试发送飞行前请求,通常是OPTIONS调用。 It expects a response from the server with the Access-Control-Allow-Origin header in the response; 它期望服务器响应,并在响应中带有Access-Control-Allow-Origin标头。 however, compliance standards restrict this response header to contain only one url in that header (or the wildcard *). 但是,遵从标准限制此响应标头在该标头(或通配符*)中仅包含一个 url。

The server you are hitting appears to be sending multiple values. 您要命中的服务器似乎正在发送多个值。

You'll need to fix the server response to only send back the wildcard or make your request through a proxy. 您需要修复服务器响应,以便仅发送回通配符或通过代理发出请求。

EDIT: Your headers are null because headers are not sent with the pre-flight request unless the withCredentials requestOptions are used. 编辑:您的标头为空,因为除非使用withCredentials requestOptions,否则标头不会随预检请求一起发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM