[英]Header name must be a valid HTTP token ["Authorization "] in postman
我在通过 postman 连接到 pexel 站点 api 时遇到问题,它给了我同样的错误:
错误:Header 名称必须是有效的 HTTP 令牌 [“授权”]
我不知道该怎么办,谢谢你帮助我:)
您可以使用 http.Client() 代替,如下所示:
class API_Manager {
Future<Model> getData() async {
var client = http.Client();
var Model;
String url =
'https://examplelink.com';
String basicAuth = 'Basic your_auth_key_here';
try {
var response = await client.get(url,
headers: <String, String>{'authorization': basicAuth});
print(response.statusCode);
developer.log(response.body); //to get your json data
if (response.statusCode == 200) {
var jsonString = response.body;
var jsonMap = json.decode(jsonString);
Model = MyModel.fromJson(jsonMap);
}
} catch (Exception) {
return Model;
}
return Model;
}
}
我找到了答案,我们必须在标题中手动编写这部分:)
header(内容类型:应用程序/json)和请求有效负载/数据之间应该有一个空换行符。
PATCH http://localhost:5000/users/61b6356454f499270755aee9
content-type: application/json
{
"first_name": "John"
}
你必须在你的身体前放一个空行
POST http://localhost:3000/api/report/expense/create HTTP/1.1
Content-Type: application/json
{
"source": "Business",
"amount": 200
}
POST http://localhost:3000/api/report/expense/create HTTP/1.1
Content-Type: application/json
{
"source": "Business",
"amount": 200
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.