简体   繁体   English

对 Django DRF 调用的 POST 请求在 cURL 中工作但不适用于 Postman

[英]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 .我按照说明支持TokenAuthentication在我的REST的API的网站,显示在这里 Using cURL, I have been able to obtain my user's token (username - example, password - example), through the following command:使用 cURL,我已经能够通过以下命令获取我的用户令牌(用户名 - 示例,密码 - 示例):

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.然而,当我通过 Postman 做(我认为是)同样的事情时,它根本不起作用。 See image below.见下图。

邮递员回复

From the error code (400 - Bad request), it seems like it's not even receiving the POST parameters at all.从错误代码(400 - 错误请求)来看,它似乎根本没有收到 POST 参数。 Can anyone help me here?有人可以在这里帮助我吗?

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.附有带有 URL 的查询字符串。因此,从 URL 中删除该查询字符串,并将参数作为这样的发布请求发送。

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

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解决方法:不要在地址栏中输入用户名和密码,而只是

在此处输入图片说明

and in body put json data of your username and password as below并在正文中放入您的用户名和密码的json数据,如下所示

在此处输入图片说明

be careful, don't use single quotation marks'', but use double quotation marks "" instead, otherwise will fail, no clue why注意,不要用单引号'',而是用双引号"",否则会失败,不知道为什么

根据您的 API 的设置方式,您可能需要在请求标头中指定内容类型Content-Type: application/json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM