api - 如何向网络服务器发送正确的curl命令

标签 api curl

所以我得到了发送到特定服务器的数据。现在,我想在本地计算机上使用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 是正确的,因此有两种可能的情况:

  1. 这与 SSL 有关吗? (我使用 --insecure 因为否则会收到 SSL 错误)
  2. 我的命令有些不正确,但我不知道是什么。

有人可以帮我吗?我正在尽我所能,但没有成功

最佳答案

我不确定我是否理解您的具体应用程序,但可能您需要考虑一件事:

男人 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/

相关文章:

html - Cocoa:从字符串显示 HTML

php - 如何在使用 Piwik 进行分析的页面上显示点击/访问计数器

curl - 如何使用curl命令行通过HTTP基本身份验证访问网页

docker - 为什么我发布的端口不起作用?

windows - 如何在 Windows 上将 Chrome 的 "Copy as cURL"用于多部分/表单数据发布请求?

php - 如何使用 Alexa 统计信息(公式?)计算网站的页面浏览量

javascript - 如何设计具有多个回调的 Javascript 库 API?

php - 一起使用 Laravel 和 Lumen

http - 当请求有正文时,Go http 上下文无法捕获取消信号(curl, postman )

ruby-on-rails - RestClient mailgun 错误 "message": "' from' parameter is missing"