Flutter Web httpOnly Cookie 未保存

Flutter Web httpOnly Cookies not saved

我有一个 Spring 引导网络服务器,它给我一个 httpOnly cookie(带有 JWT)以进行身份​​验证。

Postman 一切都很好。

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

我希望你能帮助我!

Screenshot

我找到了解决方案。

您需要设置:

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