0
我有一个应用程序,我需要击中远程服务器来获取数据,为此我使用sample.js作为中介。但是当我运行这个文件时,我收到以下错误。“套接字挂断错误”,同时点击node.js中的远程服务器
插座挂断
我在sample.js
var qs = require('querystring');
var http = require('https');
var options = {
"method": "post",
"hostname": "xxx",
"port": null,
"path": "/xxx",
"headers": {
"authorization": "xxx",
"content-type": "application/x-www-form-urlencoded",
"cache-controller": "no-cache",
"postman-token": "xxx"
}
};
var myToken = "";
var req = http.request(options, function(res) {
var chunks = [];
res.on("data", function(chunk) {
chunks.push(chunk);
});
res.on("end", function() {
var body = Buffer.concat(chunks);
myToken = body.toString();
req.write(qs.stringify({
glba: 'otheruse',
dppa: 'none'
}));
req.end();
});
});
代码我不知道这个错误的,任何人都可以请建议我帮忙吗?
嗨Aky_0788,我实际上是新的这个。可以请你解释一下'也尝试增加超时选项',以及如何增加超时..... – Niton
是这样的.... setTimeout( function(){res.end()},100); – Niton
编辑答案 –