Dart BrowserClient POST不包括我的Cookie [英] Dart BrowserClient POST not including my cookies

查看:228
本文介绍了Dart BrowserClient POST不包括我的Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我收到的回应:



>



当我发送另一个POST请求时,我没有看到包含的Cookie:





直接进入测试页面,我可以看到包含的cookies:






我用来做POST的Dart代码:

  var client = new BrowserClient 

client.post(url,body:request,headers:{Content-Type:application / json,Access-Control-Allow-Credentials:true}) (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- ,没有任何变化。



我缺少在服务器端需要在响应上设置的标题,或者是Dartium阻止跨域Cookie?



有关信息安全以及通过服务器设置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

解决方案

对于要发送到的Cookie CORS请求,您需要设置 withCredentials = true http 包中的浏览器客户端不支持此参数。您可以改用 HttpRequest dart:html
有关示例,请参见如何使用dart-protobuf


I'm doing a BrowserClient POST across domains and don't see my cookies being included.

This the response I'm getting:

When I send another POST request, I don't see the cookies being included:

Going straight to the test page, I can see the cookies being included:

The Dart code I use to make a POST:

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();
    });

Not sure about the Access-Control-Allow-Credentials header I'm including, with or without it, nothing changes.

Am I missing headers on the server side that needs to be set on the response or is Dartium blocking cross-domain cookies?

More details on Information Security and the reasoning behind setting cookies via the server.

Update: Enhancement request logged: https://code.google.com/p/dart/issues/detail?id=23088

Update: Enhancement implemented, one should now be able to do var client = new BrowserClient()..withCredentials=true; based on https://github.com/dart-lang/http/commit/9d76e5e3c08e526b12d545517860c092e089a313

解决方案

For cookies being sent to CORS requests, you need to set withCredentials = true. The browser client in the http package doesn't support this argument. You can use the HttpRequest from dart:html instead. See How to use dart-protobuf for an example.

这篇关于Dart BrowserClient POST不包括我的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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