跳到主要内容
CNode

NodeJs http请求https, https 如何忽略证书认证

问答
RRelax1989发布于 10 年前最后回复 10 年前
7273340

有个需求,请求的地址是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)

R
Relax1989#710 年前
引用 wuchangming试试加上这个

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

W
wuchangming#610 年前

试试加上这个

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
Z
zp1112#510 年前

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

R
Relax1989#410 年前
引用 zp1112看这个官方文档https://nodejs.org/api/https.html https https request options callback

@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:
L
ljcqx#310 年前

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

Z
zp1112#110 年前

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

agent = new https.Agent(agentOptions);

参与回复

登录后即可参与回复。登录