【发布时间】:2014-07-18 04:12:25
【问题描述】:
我正在从我的 php 和 Node.js 应用程序对返回 Json 对象的客户端提供的特定 URL 进行 REST API 调用。它适用于 PHP。但是,我无法从我的节点应用程序接收数据?有人可以帮助我的可能原因是什么?
注意:出于安全原因,我粘贴了一个虚拟 REST URI
- 它可以很好地与 PHP 一起工作,事实上我在几秒钟内就可以得到 json 格式的数据。
$响应 = file_get_contents('http://xyz.net/v2_resmgr/providers/pools');回声 $响应;
- 我使用 node.js 尝试相同的 url,但出现 TimeOut 错误。我也试过设置超时,但还是不行。
var job = new CronJob({ cronTime: '0 */3 * * * *', onTick: 函数 () {
url= "http://xyznet/v2_resmgr/providers/pools"; var request = http.get(url, function (response) { var buffer = "", data, route; response.on("data", function (chunk) { buffer += chunk; }); response.on("end", function (err) { console.log(buffer); }); request.setTimeout( 200000, function( ) { // handle timeout here console.log("Time Out call to the Rest API"); }); }); }, start: true }); job.start();
【问题讨论】:
标签: javascript json node.js rest