[英]Node.js http request not ending
我的node.js http.request調用有問題。 我想調用外部api(在我的情況下為Openstack api)。請求已成功發送並得到響應,但收到響應后我的請求未完成。 而是等待大約2分鍾,然后請求結束。 當從諸如Postman之類的REST客戶端執行相同的REST調用時,無需等待,一切運行良好。
這是我的代碼,在/ auth URL上執行GET請求時會調用該函數。
var options = {
host: 'someIp',
path: '/auth',
method: 'GET',
headers: {
"Host":"auth.api.someIp",
"X-Auth-User":"username",
"X-Auth-Key":"key"
}
};
var request = http.request(options, function(response){
var body = ""
response.on('data', function(data) {
body += data;
});
response.on('end', function() {
console.log('response end')
});
});
request.on('error', function(e) {
console.log('Problem with request: ' + e.message);
});
request.on('end', function() {
console.log('request end');
});
request.end();
這是控制台日志:
響應結束GET / auth 200 120080ms
我的問題是,為什么用node.js http.request進行處理時請求沒有結束?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.