Http选项方法与Javascript请求 [英] Http Option Method with Javascript request

查看:151
本文介绍了Http选项方法与Javascript请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用backbone.js的模型。当我保存模型,它发送HTTP OPTIONS方法到服务器端在firefox,但发送HTTP POST方法与safari。

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.

我知道这不是一个关于骨干的问题.js,它是关于CORS。我将检查如果方法,GET,POST,PUT和DELETE在服务器端,我不会做一个工作与HTTP OPTIONS方法。

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.

我请求的URL是我的api:api.foo.com
and api request from:bar.com

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

所以,如何控制所有浏览器请求我的api.foo.com与HTTP POST不是选项?
,以及如何与任何其他域的所有请求共享api.foo.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?

注意:我已经更改了响应的头从服务器端到:Access-Control-Allow-Origin:*

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

推荐答案

OPTIONS请求实际上是所谓的 预检请求。这个预检请求被web浏览器用来检查在什么条件下服务器将接受来自相应源的请求。如果对预检请求的响应令人满意,浏览器将发送实际请求。

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.

这篇关于Http选项方法与Javascript请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆