0

Hello I am using Angular 6 and I am trying to a http post.

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"

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.

what would cause this?

2 Answers 2

2

Modern browsers using CORS will attempt to send a pre-flight request, usually an OPTIONS call. It expects a response from the server with the Access-Control-Allow-Origin header in the response; however, compliance standards restrict this response header to contain only one url in that header (or the wildcard *).

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.

Sign up to request clarification or add additional context in comments.

Comments

1

I had the same error recently, just add proxy.json file that contains a json that defines real proxy to server and add it to start script

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.