【问题标题】:Cors issues with angular dart - cookies not set角飞镖的Cors问题-未设置cookie
【发布时间】:2020-03-23 09:38:33
【问题描述】:

我在客户端使用 angular.dart 并在服务器端使用 dart 开发应用程序。 我已经编写了一个登录休息入口点,并想设置响应中的标头但未设置 cookie。

set-cookie:app-user=533c1470a2658184a7625d7d; Expires=Tue, 8 Apr 2014 9:15:47 GMT; Domain=.ballr.eu; Path=/
set-cookie:app-tokn=530fa71b615e168787a7cb5b5c589a5601065e1e3f921d4b770c784394de3a42; Expires=Tue, 8 Apr 2014 9:15:47 GMT; Domain=.ballr.eu; Path=/

我尝试检查我的标题或我在 cookie 中设置的值,但我认为这很好

标题:

request.response..statusCode=HttpStatus.OK
                ..headers.set(HttpHeaders.CONTENT_TYPE, 'text/plain: charset=UTF-8')
                ..headers.add("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE")
                ..headers.add("Access-Control-Allow-Headers", "origin, x-requested-with, content-type, accept")
                ..headers.add("Access-Control-Allow-Origin", "*");

饼干:

static setCookie(HttpRequest request, String key, String value, DateTime duration) => 
  request.response.cookies.add(new Cookie(key, value)..path  = '/'
                                                  ..expires  = duration
                                                  ..domain   = '.app.eu');

我在stackoverflow和google组上关注了一些线程,我认为这是我在另一个项目(angular/Java)中设置的值“withCredientals”的问题,但我在angular.dart上找不到这个参数。

你能帮我找到它或者你有什么想法吗?

感谢您的帮助/时间

【问题讨论】:

    标签: cookies dart cross-domain angular-dart


    【解决方案1】:

    我不确定我是否正确理解了你的问题,但也许这就是你要找的:

    (在客户端)

      var request = new HttpRequest()
        ..open("POST", uri.toString(), async: true)
        ..withCredentials = true // seems to be necessary so that cookies are sent
    

    编辑
    我错过了这是关于 Angular 的。这需要稍微不同的方法。

    如果你使用 Angular http 服务,你有一个参数

    class MyController {
      Http _http;
      MyController(this._http) {
        _http.getString('someurl', withCredentials: true).then((e) => ...);
        // or _http.request('someurl', method: 'POST', withCredentials: true).then((e) => ...);
      }
    }
    

    【讨论】:

    • 谢谢 EDIT 工作,我直接使用_http.put 或_http.post 时找不到。现在我要写一个服务来不要忘记它。非常感谢你,你有我到文档的链接还是你凭记忆写的?祝你有美好的一天
    猜你喜欢
    • 2022-11-02
    • 2019-09-08
    • 2017-01-31
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多