Http Option Method with Javascript request

2019-04-27 03:49发布

问题:

I use backbone.js' s model. When i save the model, it sends HTTP OPTIONS method to server-side on firefox, but sends HTTP POST method with safari.

I know it is not an issue about backbone.js, it is about CORS. I will just check if method, GET, POST, PUT and DELETE on server-side, i will not do a job with HTTP OPTIONS method.

my requested url is my api: api.foo.com and api requested from: bar.com

so, how can i control in all browsers request my api.foo.com with HTTP POST not OPTIONS? and how can i share api.foo.com' s content with all request from any other domains?

Note: i have already changed response' s headers from server-side to: Access-Control-Allow-Origin: *

回答1:

The OPTIONS request is actually the so called preflight request of the CORS specification. This preflight request is used by web browsers to check under what conditions the server would accept a request from the respective origin. If the response to the preflight request was satisfying, the browser will send the actual request.

So to comply with this specification, you need your server to reproduce the steps of preflight request processing.