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
編輯答案 –