【发布时间】:2021-07-26 12:51:37
【问题描述】:
我有一个 Spring Boot Web 服务器,它为我返回一个 httpOnly cookie(带有 JWT)以进行身份验证。
Postman 一切都很好。
但是当我在 Flutter 中发送请求时,浏览器中没有保存 httpOnly cookie。
希望你能帮我解决这个问题!
【问题讨论】:
标签: spring spring-boot flutter dart flutter-web
我有一个 Spring Boot Web 服务器,它为我返回一个 httpOnly cookie(带有 JWT)以进行身份验证。
Postman 一切都很好。
但是当我在 Flutter 中发送请求时,浏览器中没有保存 httpOnly cookie。
希望你能帮我解决这个问题!
【问题讨论】:
标签: spring spring-boot flutter dart flutter-web
我找到了解决办法。
你需要设置:
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);
【讨论】: