信头名称必须是postman中的有效HTTP记号[“Authorization“]

nsc4cvqm  于 2022-11-07  发布在  Postman
关注(0)|答案(5)|浏览(226)

我在通过 Postman 连接pexel站点api时遇到了麻烦,它给了我同样的错误:
错误:标头名称必须是有效的HTTP标记[“Authorization“]
我不知道该怎么办,谢谢你帮我:)

gwbalxhn

gwbalxhn1#

标题(内容类型:应用程序/JSON)和请求有效负载/数据。

PATCH http://localhost:5000/users/61b6356454f499270755aee9
content-type: application/json

{
  "first_name": "John"
}
q9rjltbz

q9rjltbz2#

你必须在你的身体前面放一个空行

无效

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
}
swvgeqrz

swvgeqrz3#

您将授权密钥放在标头参数中
{“授权:您的API密钥”}
here查找更多信息

q9rjltbz

q9rjltbz4#

您可以改用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;
      }
    }
5lhxktic

5lhxktic5#

我找到了答案,我们必须在标题中手动写这部分:)

相关问题