为什么我会看到我从烧瓶中发送的饼干到浏览器中的颤动?
我正在创建一个需要登录验证的Flutter Web应用程序。用户将提供带有身份验证信息的发布请求,然后将我的flask应用程序发送给客户端。
这是烧瓶应用程序的代码
@app.route('/test', methods=['POST'])
@cross_origin(supports_credentials=True)
def test():
resp = jsonify({'message' : 'Logged in!'})
resp.set_cookie('Set-Cookie', "token", httponly = True, secure = False)
return resp
,这是我提出邮政请求的飞镖/颤音代码,并期望一个称为“ set-cookie”的cookie。
class HttpService {
static var dio = Dio();
static testMethod() async {
try {
dio.options.extra['withCredentials'] = true;
var response = await dio.post('http://127.0.0.1:5000/test');
print(response);
} catch (e) {
print(e);
}
}
如您所见,我不会在浏览器上收到此cookie,但是请求成功,我收到了JSON消息!
但是,当我对Postman提出同样的请求时,我会得到JSON响应和Cookie 。
任何帮助将不胜感激!让我知道您是否需要更多详细信息/代码。
I am creating a Flutter Web app that requires login verification. The user makes a post request with authentication information and then my Flask app with send a cookie back to the client.
Here is the code for the Flask App
@app.route('/test', methods=['POST'])
@cross_origin(supports_credentials=True)
def test():
resp = jsonify({'message' : 'Logged in!'})
resp.set_cookie('Set-Cookie', "token", httponly = True, secure = False)
return resp
Here is the Dart/Flutter code where I make the POST request and expect a cookie called 'Set-Cookie'.
class HttpService {
static var dio = Dio();
static testMethod() async {
try {
dio.options.extra['withCredentials'] = true;
var response = await dio.post('http://127.0.0.1:5000/test');
print(response);
} catch (e) {
print(e);
}
}
As you can see, I don't receive this cookie on my browser, but the request is successful and I get the JSON message!
BUT, when I make this same request on Postman, I get the JSON response AND the cookie.
Any help would be greatly appreciated! Let me know if you need any more details/code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 kris ,我意识到我是从flutter(client)提出请求到ip而不是域名 localhost 。因为设置cookie是特定于域的,所以我看不到开发人员控制台中的cookie设置。
这是更新的代码
Thanks to Kris, I realized I was making the request from Flutter (Client) to an IP rather than the domain name localhost. Because setting a cookie is domain specific, I couldn't see the cookie set in the developer console.
Here is the updated code