jhc
jhc

Reputation: 1759

POST request to Django DRF call working in cURL but not with Postman

I'm following the instructions to support TokenAuthentication in my rest-api site, shown here. Using cURL, I have been able to obtain my user's token (username - example, password - example), through the following command:

curl -X POST -d "username=example&password=example" localhost:8000/api/login/

This returns a successful response, with example's authentication token.

Yet when I do (what I think is) the same thing through Postman, it simply does not work. See image below.

Postman response

From the error code (400 - Bad request), it seems like it's not even receiving the POST parameters at all. Can anyone help me here?

Upvotes: 1

Views: 2399

Answers (3)

Ro Ma
Ro Ma

Reputation: 59

Even this is very old question, but if this answer would be helpful... I had exactly same issue

solution: don't put username and password in address bar,but only

enter image description here

and in body put json data of your username and password as below

enter image description here

be careful, don't use single quotation marks'', but use double quotation marks "" instead, otherwise will fail, no clue why

Upvotes: 1

Rahul Gupta
Rahul Gupta

Reputation: 520

See your URL in postman. There is attached query String with the URL.So remove that query String from the URL and send parameters as a post request like this.

http://localhost:8000/api/login/

Upvotes: 1

MrName
MrName

Reputation: 2529

Depending on how your API is set up, you probably need to specify the content type in your request headers, Content-Type: application/json.

Upvotes: 0

Related Questions