无法通过Flutter访问HTTP响应中的Cookie

问题描述 投票:0回答:1

我正在使用Flutter应用,该应用将使用基于Express的REST API。在实施基于Cookie的会话时,我想从具有基本身份验证请求的应用程序中检索Cookie,但以某种方式无法以响应方式检索Cookie。当我从邮递员发出相同的请求时,没有问题,cookie会自动设置。

我正在使用HTTP程序包发出请求,并且代码非常简单,如下所示。

void login(String username, String password) async {
var url = 'http://$username:[email protected]:3333/auth';
var response = await http.get(url);
print('Response header: ${response.headers}');
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
}

响应的标题或正文中没有cookie。

http cookies flutter dart
1个回答
0
投票

您必须在标题中调用'set-cookie':

var cookies = response.headers['set-cookie'];
© www.soinside.com 2019 - 2024. All rights reserved.