Flutter Web:如何发送不记名令牌?

mm *_* sh 0 bearer-token flutter flutter-web

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

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

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

有什么问题 ?

更新

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

ani*_*udh 5

使用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',
    });
Run Code Online (Sandbox Code Playgroud)