訪問餅乾我創建的API /用戶/ AUTH哪裏可以使用POST JSON對象像發送:與角或Javascript
var user = {"username":"alex", "password":"m"}
$http(
{
method: 'POST',
url: '/api/v1/user/auth',
data: user,
}
).
success(function(data, status, headers, config) {
console.log(data)
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
從Django中的反應如下:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Content-Type,*
Access-Control-Allow-Methods:POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin:*
Content-Language:fr
Content-Type:application/json
Date:Fri, 30 Aug 2013 15:22:01 GMT
Server:WSGIServer/0.1 Python/2.7.5
Set-Cookie:sessionid=w63m0aoo8m3vfmvv0vk5d6w1708ftsrk; Path=/
Vary:Accept, Accept-Language, Cookie
所以Django返回一個好的cookie,但我不知道爲什麼,Chrome並沒有在Resource中設置這個cookie。
請求從127.0.0.1:8000發送到127.0.0.1:8080;我用這個middleware處理CROS請求,我還設置:
SESSION_COOKIE_HTTPONLY = False
可悲的是它不工作...我將'*'更改爲127.0.0.1,但cookie未設置:( –