我正在跨域进行BrowserClient POST,但看不到包含我的cookie。
这是我得到的答复:
当我发送另一个POST请求时,我看不到包含的cookie:
直接转到测试页面,我可以看到其中包含的cookie:
我用来进行POST的Dart代码:
var client = new BrowserClient();
client.post(url, body: request, headers:{"Content-Type" : "application/json", "Access-Control-Allow-Credentials":"true"}).then((res) {
if (res.statusCode == 200) {
var response = JSON.decode(res.body);
callback(response);
} else {
print(res.body);
print(res.reasonPhrase);
}
}).whenComplete(() {
client.close();
});
不知道我包含的Access-Control-Allow-Credentials header ,无论是否包含它,都不会发生任何变化。
我是否在服务器端缺少需要在响应中设置的 header ,还是Dartium阻止了跨域Cookie?
有关Information Security的更多详细信息以及通过服务器设置cookie的原因。
更新:已记录增强请求:https://code.google.com/p/dart/issues/detail?id=23088
更新:已实现增强功能,现在应该能够基于以下功能执行
var client = new BrowserClient()..withCredentials=true;
https://github.com/dart-lang/http/commit/9d76e5e3c08e526b12d545517860c092e089a313
最佳答案
对于发送到CORS请求的Cookie,您需要设置withCredentials = true
。 http
包中的浏览器客户端不支持此参数。您可以改用HttpRequest
中的dart:html
。
有关示例,请参见How to use dart-protobuf。
关于cookies - Dart BrowserClient POST不包括我的cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29427203/