cURL 与 Postman,对 HTTPS POST 的不同响应

问题描述 投票:0回答:2

我们正在为客户端设置报告源,并且在测试端点时,我们在 cURL(命令行)和 Postman 之间收到不同的响应。在 Postman 中,请求顺利通过;我们得到了 200-OK 的回复。但是,当我们在 cURL 中发送请求时,我们会收到以下响应

curl: (60) SSL certificate problem: certificate has expired

带卷曲

cURL 请求如下所示:

curl -i -H "content-type: application/json" -d '{"foo": [],"bar": [],"baz": []}' https://test.example.com/notARealEndpoint

与邮递员

Postman 设置很难显示,但它的代码转换如下:

cURL解释

curl --location --request POST 'https://test.example.com/not/aReal/Endpoint' --header 'Content-Type: application/json' --header 'Content-Type: text/plain' --data-raw '{"foo": [],"bar": [],"baz": []}'

*顺便说一下,在命令行中运行时会返回相同的

certificate has expired
错误

HTTP解释

POST /not/aReal/Endpoint HTTP/1.1
Host: test.example.com
Content-Type: application/json
Content-Type: text/plain

{"foo": [],"bar": [],"baz": []}
ssl curl postman tls1.2
2个回答
1
投票

目标服务器的 SSL 证书似乎已过期。邮递员没有引发错误的原因可能是因为禁用了 SSL 验证检查。

您可以使用

--insecure
-k
选项禁用curl 中的这些检查。 例如:

curl https://expired.badssl.com

会抛出与您所看到的相同的错误。 与

curl --insecure https://expired.badssl.com

将返回 html 响应正文。


0
投票

我知道这是一个有点过时的问题,但我也遇到了同样的问题。

事实证明,在 Postman 中,有一个“遵循原始 HTTP 方法”的选项,该选项对我来说是关闭的。打开它后,我得到了与curl一样的正确响应

© www.soinside.com 2019 - 2024. All rights reserved.