【问题标题】:Flutter Web httpOnly Cookies not savedFlutter Web httpOnly Cookies 未保存
【发布时间】:2021-07-26 12:51:37
【问题描述】:

我有一个 Spring Boot Web 服务器,它为我返回一个 httpOnly cookie(带有 JWT)以进行身份​​验证。

Postman 一切都很好。

但是当我在 Flutter 中发送请求时,浏览器中没有保存 httpOnly cookie。

希望你能帮我解决这个问题!

Screenshot

【问题讨论】:

    标签: spring spring-boot flutter dart flutter-web


    【解决方案1】:

    我找到了解决办法。

    你需要设置:

    withCredentials = true;

    完整代码:

     Future<http.Response> authenticationFromUser(
      String username, String password) async {
    var client = BrowserClient()..withCredentials = true; // <====
    http.Response response;
    Map data = {"username": username, "password": password};
    String body = json.encode(data);
    
    return response = await client.post(
        Uri.parse("http://localhost:8080/auth/login"),
        headers: {"Content-Type": "application/json"},
        body: body);
    

    【讨论】:

      猜你喜欢
      • 2021-04-30
      • 2020-12-22
      • 1970-01-01
      • 2021-07-05
      • 2021-11-17
      • 2011-01-17
      • 2021-07-19
      • 2023-02-02
      • 2023-01-02
      相关资源
      最近更新 更多