简体   繁体   English

在节点Js中结束HTTP请求

[英]Ending HTTP Request in Node Js

this my code for sending http request. 这是我发送HTTP请求的代码。 Is there anything wrong why my request doesn't end? 为什么我的请求没有结束有什么不对?

var req = http.request(options, function(res) {
        res.setEncoding('utf8');
        res.on('data', function(chunk) {
            console.log('Response: ' + chunk);
        });
    });

    req.write(uid);
    req.end();         //i think this line will end the requset, but not.

Thanks for the answer guys. 谢谢你们的回答。

I found out that i missed to end the response with res.end(); 我发现我错过了以res.end();结尾的响应res.end();

    var req = http.request(options, function(res) {
        res.setEncoding('utf8');
        res.on('data', function(chunk) {
        console.log('Response: ' + chunk);
        });
    });

    req.write(uid);
    req.end();
    res.end();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM