我想使用request
模块生成简单的POST HTTP请求:
var request = require("request");
var form = {form: {some: "form", attributes: "attrs"}}
request.post("https://example.com", form)
.on('response', function(response) {
if (response.statusCode === 200) {
console.log("DONE");
} else {
console.log("FAIL");
}
});
当我启动此代码时,它会抛出此错误消息:
Error: unable to verify the first certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1057:38)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket._finishInit (_tls_wrap.js:596:8)
我认为这是因为网址有https
,但我不知道如何修复此错误。
如何禁用检查证书?
答案 0 :(得分:5)
添加"rejectUnauthorized": false
作为选项:
request.post({url: "https://example.com", "rejectUnauthorized": false}, form)
.on('response', function(response) {
if (response.statusCode === 200) {
console.log("DONE");
} else {
console.log("FAIL");
}
});
或通过https://www.npmjs.com/package/ssl-root-cas
添加适当的证书require('ssl-root-cas').inject();
答案 1 :(得分:1)
您可以尝试在“文件”->“设置”下禁用ssl证书验证 Settings image