通过node.js中的http.request()在每个请求中获取请求超时
我使用nodejs http.request方法将一些数据发布到外部API。 我testing像这样:
var options={ hostname:'www.google.com', port:80, method:'POST' }; var req=http.request(options,function(res){ console.log('STATUS: ' + res.statusCode); console.log('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('BODY: ' + chunk); }); }); //console.log(req); req.on('error', function(e) { console.log('problem with request: ' + e.message); });
这整个包裹在一个快递服务器后的路线。 但在控制台,它总是说在一段时间后连接超时。 我无言以对
你只是简单地创build一个request
对象。 你也必须发送它。 使用req.end()
来实际发送请求。
req.on('error', function(e) { console.log('problem with request: ' + e.message); }); req.end(); //add it
- Primus with Express
- 在node.js中使用express.loggerlogging错误
- Node.js:在OpenShift上提供静态资源问题
- nodejs,socket.io和expressjs不能连接
- nodeJSvideostream,当用户断开或移动到不同的页面时,连接不会closures
- 将Express React Redux模板部署到Heroku的步骤
- types错误:对象{…}没有方法“查找” – 当使用expression的mongoose
- 如何configurationexpressjs来处理http和https?
- 在websockets上运行socket.io错误404