NodeJs http请求https, https 如何忽略证书认证
发布于 7 年前 作者 Relax1989 24673 次浏览 来自 问答

有个需求,请求的地址是https 的, 但是不需要证书验证
在Nodejs 中 我用http模块去发起请求报错,发送不过去 直接异常
code: 'HPE_INVALID_CONSTANT’ 还有一个异常

用https模块发送请求,一直要求我要证书
EPROTO 101057795:error:14082174:SSL routines:ssl3_check_cert_and_algorithm:dh key too small:openssl\ssl\s3_clnt.c

但是我使用工具发送请求却可以,请求的头内容如下 Request URL: https://test5-oauth.stg.1qianbao.com:29443/map/oauth Request Method: POST Status Code: 200 OK Request Proto: HTTP/1.1 Request Header Content-Type:application/x-www-form-urlencoded;

Response Header Server:Apache-Coyote/1.1; Content-Type:application/json;charset=utf-8; Date:Thu, 17 Nov 2016 11:51:57 GMT;

请问这种在NodeJs如何实现, 如何使用 http 请求https 或者说,如何去除https中证书验证

7 回复

agentOptions = { host: ‘www.12306.cn’, port: ‘443’, path: ‘/’, rejectUnauthorized: false };

agent = new https.Agent(agentOptions);

看这个官方文档https://nodejs.org/api/https.html#https_https_request_options_callback

请使用request模块,更好用, 或者superagent模块也可以

@zp1112 按照你上面的方法尝试了 options = { host: ‘test5-oauth.stg.1qianbao.com’, port: 29443, path: ‘/map/oauth’, method: ‘POST’, rejectUnauthorized: false, headers: {‘content-type’: ‘application/json’} }, options.agent = new https.Agent(options);

https.Request 的时候, 直接抛出异常
Error: write EPROTO 101057795:error:14082174:SSL routines:ssl3_check_cert_and_algorithm:dh key too small:openssl\ssl\s3_clnt.c:3617:

@Relax1989 port:29443是啥???https端口不该是443么?

试试加上这个

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'

@wuchangming 不管哦, https 如何忽略证书?

回到顶部