【发布时间】:2022-08-19 19:11:28
【问题描述】:
我有一个基于令牌的 API,它在 Postman(或 soapUI)中运行良好,但在通过 Flutter 应用程序点击时抛出 UnauthorizedException。这是发布请求:
import \'package:http/http.dart\' as http;
final response = await http.post(
Uri.parse(url),
headers: {
\'Content-Type\': \'application/json\',
\'Accept\': \'application/json\',
\'Authorization\': \'Bearer $token\',
};,
body: jsonEncode(body),
);
经过大量挖掘,dart 的http 客户端似乎正在将标头标签转换为小写,如日志所示:
<tran:user-header name=\"authorization\" value=\"Bearer eyJhbGciOiJSU...\" />
<http:User-Agent>Dart/2.17 (dart:io)</http:User-Agent>
而使用okhttp 客户端(java)发送的相同发布请求记录:
<tran:user-header name=\"Authorization\" value=\"Bearer eyJhbGciOiJSU...\" />
<http:User-Agent>okhttp 4.9.0</http:User-Agent>
我还尝试了 dart 的 dio 包,但问题仍然存在。真的是这样还是我只是在假设一些事情?