【发布时间】:2015-06-08 05:59:03
【问题描述】:
我正在跨域执行 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 标头,不管有没有,都没有任何变化。
我是在服务器端缺少需要在响应中设置的标头,还是 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
【问题讨论】:
-
我猜你需要在你的 post 请求上设置
withCredentials=true,但我还没有找到如何处理来自 http 包的请求(比如在 stackoverflow.com/questions/21770445 或 stackoverflow.com/questions/16939328 )。 -
我可以看到在 angular.dart 中对此做了特殊规定,但在 BrowserClient github.com/dsalsbury/angular.dart/commit/… 中没有
-
如果 angular.dart 正在执行此操作,那么它肯定是在底层调用标准 dart 库,还是 angular.dart 有自己的类似 BrowserClient 的库?
-
不,在浏览器中,除了使用 dart:html 中的 HttpRequest API 之外,您不能执行 HTTP 请求。 Angular 和 browserClient 只是转发它。 http 包的创建是为了在客户端和服务器之间有一个统一的 API。在服务器上它转发到 dart:io,在浏览器上转发到 dart:html。
-
我已经记录了一个增强请求:code.google.com/p/dart/issues/detail?id=23088 同时我会降低一点,直接使用 HttpRequest。