跳过自签名请求的证书检查

请求自签名证书的 url 前(比如 12306),会提示如下错误:

Bash
curl: (60) SSL certificate problem: Invalid certificate chain
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a “bundle”
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn’t adequate, you can specify an alternate file
using the –cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you’d like to turn off curl’s verification of the certificate, use
the -k (or –insecure) option.

按照提示可以使用 -k 或 –insecure 参数,不启用证书验证发送请求

nodejs 中可以设置环境变量

JavaScript
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

然后使用 superagent 或 request 请求数据。

发表评论

电子邮件地址不会被公开。 必填项已用*标注