错误"ssl3_get_record:版本号错误";在发出https发布请求时在node.js中 [英] Error "ssl3_get_record:wrong version number" in node.js when making https post request

查看:856
本文介绍了错误"ssl3_get_record:版本号错误";在发出https发布请求时在node.js中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下脚本使用node.js向我的工作的api发出https请求

I'm trying to make a https request to an api of my work using node.js through the following script

const https = require('https');
const options = {
    hostname,
    path: fullPath,
    port: 80,
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': data.length
    }
};
const req = https.request(options, (res) => {
    console.log('statusCode:', res.statusCode);
    res.on('data', chunk => console.log('chunk:', chunk));
});
req.on('error', error => {
    console.log('Failed!');
    console.log(error);
});
req.write(data);
req.end();

作为回应,我得到了

Failed!
Error: write EPROTO 6772:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:

    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:87:16) {
  errno: 'EPROTO',
  code: 'EPROTO',
  syscall: 'write'
}

我在使用jQuery的浏览器上发出了此请求,并且有效

I made this request on a browser using jQuery and it worked

$.post({
    url, data,
    success: res => console.log(res),
});

我尝试使用标头X-SSL-PROTOCOL,但未成功.url和数据被隐藏,因为它们是机密的,但是在jQuery示例和node.js中它们是相同的.

I tryed to use the header X-SSL-PROTOCOL with no success. The url and data are hidden because they are confidential, but they are the same in the jQuery example and in node.js.

推荐答案

    port: 80,
    method: 'POST',
    ...
const req = https.request(options, (res) => {

您正在针对端口80使用HTTPS,该端口通常是纯HTTP.您得到的响应表明服务器未在此端口上提供HTTPS,这实际上是预期的行为.HTTPS通常是在端口443上完成的.

You are using HTTPS against port 80, which is usually plain HTTP. The response you get suggest that the server is not providing HTTPS on this port, which is actually the expected behavior. HTTPS is instead usually done on port 443.

我在使用jQuery的浏览器上发出了此请求,并且有效

I made this request on a browser using jQuery and it worked

尚不清楚此示例中的 url 是什么,但如果只是 https://domain/path ,则使用端口443.如果明确指定了端口80,则该端口仅用于HTTPS,即 https://domain:80/path .

It is unclear what url is in this example but if it just was https://domain/path then port 443 was used. Port 80 would have only been used with HTTPS if explicitly given, i.e. https://domain:80/path.

这篇关于错误"ssl3_get_record:版本号错误";在发出https发布请求时在node.js中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆