当我尝试使用 AJAX 和 Tastypie 执行 HTTP 请求时,我在对我的 Tastypie 资源使用 ApiKeyAuthentication 时收到以下错误:
XMLHttpRequest cannot load http://domain.com/api/v1/item/?format=json&username=popo&api_key=b83d21e2f8bd4952a53d0ce12a2314c0ffa031b1. Request header field Authorization is not allowed by Access-Control-Allow-Headers.
关于如何解决这个问题的任何想法?
以下是来自 Chrome 的请求标头:
Request Headersview source
Accept:*/*
Accept-Charset:
ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:
origin, authorization, access-control-allow-origin, accept, access-control-allow-headers
Access-Control-Request-Method:
GET
以下是来自 Chrome 的响应标头:
Response Headersview source
Access-Control-Allow-Headers:
Origin,Content-Type,Accept,Authorization
Access-Control-Allow-Methods:
POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:0
Content-Type:
text/html; charset=utf-8
Date:Fri, 11 May 2012 21:38:35 GMT
Server:nginx
如您所见,它们都有授权标头,但授权不起作用。
这是我用来编辑响应标头的 django 中间件: https ://gist.github.com/1164697
编辑:我发现了问题。我试图连接到 www.domain.com,它只接受 domain.com