如何在JSON-RPC服务器上响应HTTP OPTIONS请求 [英] How to respond to HTTP OPTIONS request on a JSON-RPC server

查看:583
本文介绍了如何在JSON-RPC服务器上响应HTTP OPTIONS请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSON-RPC客户端(使用dojo JSON-RPC的浏览器)在myserver.com/12345 上为JSON-RPC服务器发出JSON-RPC请求(dojo.callRemote)(Python 2.5, SimpleJSONRPCServer)。

My JSON-RPC client (browser using dojo JSON-RPC) makes a JSON-RPC request (dojo.callRemote) to my JSON-RPC server on myserver.com/12345 (Python 2.5, SimpleJSONRPCServer).

服务器然后获取一个HTTP请求,其头文件OPTIONS / HTTP / 1.1,默认情况下无法处理,因此我为此请求编写了一个自定义处理程序

The server then gets a HTTP request with header "OPTIONS / HTTP/1.1", which it can't handle by default, so I wrote a custom handler for this request.

浏览器中的请求标头说:

The request header from the browser says:

OPTIONS / HTTP/1.1
Host: myserver:12345
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.8) Gecko/20100214 Linux Mint/8 (Helena) Firefox/3.5.8 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.7,de;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Origin: http://myserver.com
Access-Control-Request-Method: POST
Access-Control-Request-Headers: x-requested-with

我发送的响应如下所示: p>

And the response I'm sending looks like this:

HTTP/1.0 200 OK
Server: BaseHTTP/0.3 Python/2.5
Date: Mon, 05 Apr 2010 18:58:34 GMT
Access-Control-Allow-Method: POST
Access-Control-Allow-Headers: POST
Allow: POST
Content-Type: application/json-rpc
Content-length: 0

但是在浏览器中我会收到以下错误:

But in the browser I get the following error:

错误:无法加载 http://myserver.com: 12345 状态:0

Error: Unable to load http://myserver.com:12345 status:0

我验证了可以从网络访问JSON服务。

I verified that the JSON-Service is reachable from the net.

现在的问题是,浏览器(比如说Firefox)希望响应者有什么看法?或者也许这个问题在别的地方?

Now the question is, what does the browser (say, Firefox) expect the response hearders to say? Or maybe the problem lies elsewhere?

推荐答案

请参阅 CORS规范

(BTW;有HTTP的头注册表,请参阅 http://www.iana.org/assignments/message-headers/prov-headers.html http://www.iana.org/assignments/message-headers /perm-headers.html ,这将指向您正确的规格)。

(BTW; there's a header registry for HTTP, see http://www.iana.org/assignments/message-headers/prov-headers.html and http://www.iana.org/assignments/message-headers/perm-headers.html, which would have pointed you to the right spec).

这篇关于如何在JSON-RPC服务器上响应HTTP OPTIONS请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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