Syl*_*les 7 cookies dart flutter-web
我正在尝试从 flutter web 应用程序的响应中读出 cookie。不幸的是我无法读出它,尽管浏览器可以(Brave,chromium)。我正在使用dio
进行发布请求。作为自动从响应中获取所有 cookie 的拦截器,我向其中添加了dio cookie 管理器:
var dio = Dio();
var cookieJar = CookieJar();
dio.interceptors.add(CookieManager(cookieJar));
Run Code Online (Sandbox Code Playgroud)
我还向其中添加了LogInterceptor 类。
问题是这样的:在浏览器中,我可以看到使用 chrome Dev Tools > Network 并检查请求在响应标头中设置了 cookie:
Request:
Request URL: https://123.123.123.123/api/login/password
Request Method: POST
Status Code: 200 OK
Remote Address: 123.123.123.123:443
Referrer Policy: strict-origin-when-cross-origin
Response:
Access-Control-Expose-Headers: Set-Cookie
Content-Length: 24
Content-Type: application/json
Date: Fri, 18 Jun 2021 13:55:05 GMT
Server: MyServer
Set-Cookie: my-cookie-session=123456789; Expires="Fri Jun 18 14:55:05 2021"; SameSite=Strict
Run Code Online (Sandbox Code Playgroud)
LogInterceptor 将其打印到控制台:
*** Response ***
uri: https://123.123.123.123/api/login/password
statusCode: 200
headers:
access-control-expose-headers: Set-Cookie
content-length: 24
content-type: application/json
date: Fri 18 Jun 2021 13:55:05 GMT
server: MyServer
Run Code Online (Sandbox Code Playgroud)
之后打印出罐子里有多少饼干和哪些饼干时,结果是 0 和一个空列表:
Request:
Request URL: https://123.123.123.123/api/login/password
Request Method: POST
Status Code: 200 OK
Remote Address: 123.123.123.123:443
Referrer Policy: strict-origin-when-cross-origin
Response:
Access-Control-Expose-Headers: Set-Cookie
Content-Length: 24
Content-Type: application/json
Date: Fri, 18 Jun 2021 13:55:05 GMT
Server: MyServer
Set-Cookie: my-cookie-session=123456789; Expires="Fri Jun 18 14:55:05 2021"; SameSite=Strict
Run Code Online (Sandbox Code Playgroud)
CookieCount: 0
Run Code Online (Sandbox Code Playgroud)
有人知道为什么浏览器可以读取cookie但flutter web应用程序不能?此外,浏览器中没有设置cookie,我只能在如上所述检查网络请求时显示它。
| 归档时间: |
|
| 查看次数: |
912 次 |
| 最近记录: |