使用 Postman 创建 POST 请求

Create POST Request with Postman

此 curl 工作正常,return按预期使用令牌:

curl -X POST -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{ "username": "pere.peris@gmail.com","password": "password" }' "http://75.90.255.68:1133/canPeris/auth"

但是当我使用 Postman 应用进行相同的调用时,我得到一个 401 Unauthorized 作为 return 值

您应该在 Body 中添加缺少的 JSON 。单击原始组合框并添加

{ "username": "pere.peris@gmail.com","password": "password" }

您可以使用Postman中的函数生成curl: https://www.getpostman.com/docs/v6/postman/sending_api_requests/generate_code_snippets

在 "Send" 和 "Save" 下方的右侧,只需点击代码 Button/Link。然后在下拉 cURL 的下一个 window 中 select。所以你看到会生成什么 cURL 并将其与命令行进行比较。

此处描述了 -d 选项:https://curl.haxx.se/docs/manpage.html#-d