所以我得到了发送到特定服务器的数据。现在,我想在本地计算机上使用curl 执行相同的操作,以处理来自服务器的特定响应并了解有关curl 的更多信息。
这是我的部分数据
POST /auth HTTP/1.1
platform: android
X-Auth-Token: <censored>
Content-Type: application/json; charset=utf-8
Host: api.blabla.com
Accept-Encoding: gzip
以及正在发送的数据:
{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}
现在,当我在 dos shell 中尝试 cURL 时,我会尝试
curl --insecure -X POST https://api.blabla.com/auth --data '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}'
我从 cURL 得到的响应是这样的:
{"code":401,"error":"blablaTokenRequired"}
即使我指定了 token 。因此,由于 token 是正确的,因此有两种可能的情况:
- 这与 SSL 有关吗? (我使用 --insecure 因为否则会收到 SSL 错误)
- 我的命令有些不正确,但我不知道是什么。
有人可以帮我吗?我正在尽我所能,但没有成功
最佳答案
我不确定我是否理解您的具体应用程序,但可能您需要考虑一件事:
男人 curl 说:
-d, --data <data>
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when
a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the
server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.
-d, --data is the same as --data-ascii. --data-raw is almost the same but does not have a special interpreta‐
tion of the @ character. To post data purely binary, you should instead use the --data-binary option. To URL-
encode the value of a form field you may use --data-urlencode.
由于我在您的示例中看不到将数据作为 HTML 表单输入发送的必要性,因此您的应用程序可能需要一个“原始”POST 正文,然后您必须尝试以下操作: p>
curl --insecure -X POST https://api.blabla.com/auth --data--binary '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}'
PS,可以肯定的是,这个错误与使用--insecure
无关,它只是要求curl忽略ssl验证
关于api - 如何向网络服务器发送正确的curl命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35256576/