FlutterWeb:如何发送不记名令牌?

我有一个 ASP.Net Core web api,它接受不记名令牌 (jwt),我在我的 Flutter 中使用 Android 模拟器发送这个令牌,此代码没有任何问题:

final response = await get(url, headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Authorization': 'Bearer $token',
    });

但是当我在 Chrome 浏览器中运行它时,api 响应是: 405 Method Not Allowed 。

有什么问题 ?

更新

根据@anirudh 的评论,我在我的 web Api 中启用了 CROS 并且问题已经改变。现在的响应是:204 No Content

回答

使用http插件

并且做http.get 而不仅仅是get

import 'package:http/http.dart' as http;

final response = await http.get(url, headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Authorization': 'Bearer $token',
    });


以上是FlutterWeb:如何发送不记名令牌?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>