json 邮递员 - 错误 400 错误请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48489285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:06:03  来源:igfitidea点击:

Postman - Error 400 Bad Request

jsonrestapiauthenticationpostman

提问by Derrick

I'm trying to access an API using Postman to get a response using basic authentication, but when I submit the data, it gives me the dreaded 400 error, which apparently indicates that some headers aren't set up properly.

我正在尝试使用 Postman 访问 API 以使用基本身份验证获取响应,但是当我提交数据时,它给了我可怕的 400 错误,这显然表明某些标头设置不正确。

Here's the API info:

这是API信息:

Request

Endpoint: {loginUrl}
Data to submit: an email and a password
POST /login HTTP/1.1
Host: {baseUrl}
Accept: application/json
Content-Type: application/json
Content-Length: 68

{
    "email": "{email}",
    "password": "{password}"
}

And in response, I should get an encrypted token in form of JSON, instead I'm getting this error.

作为回应,我应该得到一个 JSON 形式的加密令牌,而不是我收到这个错误。

Here are the postman screenshots:

以下是邮递员截图:

Postman_01

Postman_01

Postman_02

Postman_02

Am I missing something?

我错过了什么吗?

采纳答案by Danny Dainton

From the lack of details it's difficult to offer a specific answer but I can offer something that you can try - The Requestdata you posted in the question looks like you should be adding:

由于缺乏细节,很难提供具体的答案,但我可以提供一些您可以尝试的内容-Request您在问题中发布的数据看起来应该添加:

{
    "email": "{email}",
    "password": "{password}"
}

In the Bodysection of the request but your images don't show that you've added that to the Bodyon anyrequest, you've added it as a Authheader instead, so remove that before trying again. I'm not sure of the need to add the Content-Lengthheader as that will change for different username and password combinations in the payload or for the length of the response.

Body要求的部分,但你的图像不显示你已经补充说,在Body任何要求,你添加它作为一个Auth标题来代替,因此在再次尝试之前删除。我不确定是否需要添加Content-Length标头,因为这会因负载中的不同用户名和密码组合或响应长度而变化。