CNode

nodejs 调用rest服务 并返回json 数据 响应无效

Ppylmcy150发布于12 年前最后回复12 年前3 回复11319 浏览0 收藏

通过nodejs 发送get请求,服务端响应返回了数据,但是通过res.send 方法返回数据时response无响应,不知道哪位大神能帮忙指点下。 var reqGet = http.request(optionsget, function (resGet) { resGet.on('data', function (d) { if (d && d != 'null') { var data = JSON.parse(d); req.session.user = data; //res.json(data); //console.log(JSON.stringify(data)); //res.end(JSON.stringify(data)); //var j = { u: '33556' }; //res.send(j);

                res.send(data);
            }
            else {
            }
            res.end();
        });
    });
查看回复

回复 (3)

J
jeremy16601#1·12 年前

直接res.json 不行 吗

P
pylmcy150#2·12 年前

不行,不过问题解决了,是resGet.on('end', function () {});才行;

A
AdoHe#3·12 年前

文档上面关于http.get和http.request的区别写的很清楚的。。。

参与回复
登录后即可参与回复。登录