1

I am working on Angular 1 / ASP.net tech stack based web application. For some reason, I can not deploy api server on my local env, using Production server. And I launched UI side with nginx in local env. Login page is:

http://localhost:8080/login.html

And when click login button, it calls API from production server.

http://devprod2.com/api/oauth/login

But I am getting error:

Response for preflight has invalid HTTP status code 400

I opened Cross domain option in browser, with chrome CORS extension. But it seems this error is related with some CORS problem. Would you like to help me to fix this problem?

1 Answer 1

1

A preflight request occurs when you use certain methods, e.g. POST

It is a request that automatically happens before the cross domain POST happens.

It is checking to see that the correct CORS headers are in place on the server before making the POST request.

It seems like your preflight OPTIONS request is giving an invalid response. On your server, make sure you return 200 for all OPTIONS requests and make sure the CORS headers are in place on the server for all requests.

I believe Angular 1 also has options for a POST request that will prevent preflight requests from being made but you would have to investigate this further yourself.

Alternatively, depending on your setup, it maybe possible to rewrite the request to avoid CORS which is only enforced by browsers.

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

3 Comments

@danday74- Thanks for your response. I have a question. So, I thought CORS error is occurred in browser side, so server's response is freeze in browser. That's why I expected it would work well if I enable CORS in browser. So what's happened on server if I call API from local side?
You enable CORS on the server, make sure the server response has all the CORS headers. The browser will error if the server does not return the correct CORS response headers. Also, make sure your server CORS response headers permit the preflight OPTIONS request method - see developer.mozilla.org/en-US/docs/Web/HTTP/Headers/…
Thanks. This greatly helped out me. This is something new I didn't know before! Thanks again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.