[英]Node.js http request not ending
I have a problem with node.js http.request call. 我的node.js http.request调用有问题。 I want to call external api (in my case Openstack api).The request is sent successfully and i get the response, but my request does not finish after response is received.
我想调用外部api(在我的情况下为Openstack api)。请求已成功发送并得到响应,但收到响应后我的请求未完成。 Instead it waits for about 2 minutes and then the request ends.
而是等待大约2分钟,然后请求结束。 When do the same REST call from a REST client like Postman, there is no waiting and everything works well.
当从诸如Postman之类的REST客户端执行相同的REST调用时,无需等待,一切运行良好。
Here is my code, the function is called when I do the GET request on /auth URL. 这是我的代码,在/ 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();
This is the console log: 这是控制台日志:
response end GET /auth 200 120080ms 响应结束GET / auth 200 120080ms
My question is, why is request not ending when i do it with node.js http.request? 我的问题是,为什么用node.js http.request进行处理时请求没有结束?
Mmh try listening for the finish event. 嗯,试着听完比赛。
request.on('finish', function() {
console.log('request end');
});
request is an instance of Incoming Message . request是“ 传入消息”的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.