Javascript 节点js https请求上的套接字挂起
我已经在stackoverflow和其他网站上搜索了一些教程和问题,但我仍然无法找出我的脚本产生错误的原因:套接字挂起 希望你们能帮助我 我实现了一个https服务器,如上的教程中所示 工作完美,客户也能工作。 但是当我想用javascript创建一个请求并用NodeJS运行它时,我得到了一个已知的错误 My.js文件:Javascript 节点js https请求上的套接字挂起,javascript,node.js,https,request,Javascript,Node.js,Https,Request,我已经在stackoverflow和其他网站上搜索了一些教程和问题,但我仍然无法找出我的脚本产生错误的原因:套接字挂起 希望你们能帮助我 我实现了一个https服务器,如上的教程中所示 工作完美,客户也能工作。 但是当我想用javascript创建一个请求并用NodeJS运行它时,我得到了一个已知的错误 My.js文件: var https = require('https'); var data = JSON.stringify({ firstName: 'JoaquÌn', });
var https = require('https');
var data = JSON.stringify({
firstName: 'JoaquÌn',
});
function getCall() {
//initialize options values, the value of the method can be changed to POST to make https post calls
var options = {
host : 'localhost',
port : 9999,
path : '/',
rejectUnauthorized: false,
method : 'POST',
headers: {'Connection': 'keep-alive',
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': Buffer.byteLength(data)}
}
//making the https get call
var getReq = https.request(options, function(res) {
console.log("\nstatus code: ", res.statusCode);
res.on('data', function(data) {
console.log( JSON.parse(data) );
});
});
//end the request
getReq.end();
getReq.on('error', function(err){
console.log("Error: ", err);
});
}
getCall();
我的错误:
Error: { Error: socket hang up
at createHangUpError (_http_client.js:253:15)
at TLSSocket.socketOnEnd (_http_client.js:345:23)
at emitNone (events.js:91:20)
at TLSSocket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9) code: 'ECONNRESET' }
IntelliJ在运行脚本时生成此部分:
SSLSession :
Protocol : TLSv1.2
Cipher suite : TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
Inut : POST / HTTP/1.1
Inut : Connection: keep-alive
Inut : Content-Type: application/json; charset=utf-8
Inut : Content-Length: 24
Inut : Host: localhost:9999
Inut :
我希望你能帮助我,因为我不知道为什么我会犯这样的错误。我已经尝试了几种解决方案,但没有一种对我有效
Thx和祝福Martin假设您已经有一个HTTP服务器在配置的端口上运行,您将需要将
主机:'localhost'
更改为主机:'http://localhost“
根据您设置的协议,它可以是
http
或https
。假设您已经有一个http服务器在配置的端口上运行,您需要将主机:'localhost'
更改为主机:'http://localhost“
根据您设置的协议,它可以是
http
或https
。Hey:)响应的Thx,但在将行从localhost更改为http localhost后,我得到以下响应:错误:{Error:getaddrinfo ENOTFOUNDhttps://localhost https://localhost:9999 在errnoException(dns.js:28:10)在GetAddrInfoReqWrap.onlookup[as oncomplete](dns.js:76:26)代码:“ENOTFOUND”,错误号:“ENOTFOUND”,系统调用:“getaddrinfo”,主机名:'https://localhost'主持人:'https://localhost“,端口:9999}
能否放置更新的代码。这些错误表明您正在使用https
。我假设服务器已经在上面提到的端口上运行了。很抱歉,响应太晚了,但是我们已经改变了技术方式,我们正在使用Wildfly服务器(Wildfly Swarm)要与我们的前端通信:)但非常感谢:)嘿:)Thx的响应,但在将行从localhost更改为http localhost后,我得到以下响应:Error:{Error:getaddrinfo ENOTFOUNDhttps://localhost https://localhost:9999 在GetAddrInfoReqWrap.onlookup的errnoException(dns.js:28:10)中[作为oncomplete](dns.js:76:26)代码:'ENOTFOUND',错误号:'ENOTFOUND',系统调用:'getaddrinfo',主机名:'https://localhost'主持人:'https://localhost'端口:9999}
您能否放置更新的代码。错误表明您使用的是https
。我认为服务器已经在上述端口上运行。很抱歉,响应太晚,但我们已经改变了技术方式,我们正在使用Wildfly服务器(Wildfly Swarm)与前端通信:)但非常感谢:)