Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman - Error 400 Bad Request

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.

Here's the API info:

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.

Here are the postman screenshots:

Postman_01

Postman_02

Am I missing something?

like image 939
Derrick Avatar asked Jan 28 '18 17:01

Derrick


People also ask

What causes HTTP 400 Bad Request?

The HTTP error 400 can occur due to incorrectly typed URL, malformed syntax, or a URL that contains illegal characters. This is surprisingly easy to do by mistake and can happen if a URL has been encoding incorrectly.

What does 400 there was a problem with your request mean?

What does 400 mean on Roblox? When you are receiving a 400 bad request error on Roblox on your gaming device, it simply means you are trying to access a page that is either down for maintenance or you have a firewall problem.

How do I fix HTTP error 400 a request header field is too long?

Chosen solution Clear the Cache and remove the Cookies for websites that cause problems via the "3-bar" Firefox menu button (Options/Preferences). If clearing cookies didn't help then it is possible that the cookies. sqlite file in the Firefox profile folder that stores the cookies got corrupted. rename/remove cookies.


3 Answers

I also faced the same issue and i updated my postman header with the below image. And issue solved. enter image description here

like image 165
Lokman Hosen Avatar answered Oct 16 '22 10:10

Lokman Hosen


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

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

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

like image 40
Danny Dainton Avatar answered Oct 16 '22 11:10

Danny Dainton


In case anyone finds this helpful, I ran into the same issue and the culprit turned out to be missing headers. I knew I needed the "Content-Type": "application/json" header, which I already had in place, but I didn't know that I was missing two other headers.

The solution for me was also adding the "Content-Length" and "Host" headers in Postman.

I see some others have questioned the need for the "Content-Length" header, but in my case, the minimum three needed were "Content-Type", "Content-Length", and "Host" or it would always fail.

like image 34
cf512 Avatar answered Oct 16 '22 10:10

cf512