我是靠谱客的博主 辛勤菠萝,这篇文章主要介绍nodejs做中间层_nodejs做中间层,向后端取数据,现在分享给大家,希望可以做个参考。

router.get('/', function(req, res, next) {

var post_data={username:'yuzhou001',password:'123456'};//这是需要提交的数据

var content=qs.stringify(post_data);

var options = {

host: 'www.badiu.cn',

port: 80,

path: '/api/User/Login',

method: 'POST',

headers:{

'Content-Type':'application/x-www-form-urlencoded',

'Content-Length':content.length

}

};

var req = http.request(options, function(res) {

/* console.log("statusCode: ", res.statusCode);

console.log("headers: ", res.headers);*/

var _data='';

res.on('data', function(chunk){

_data += chunk;

});

res.on('end', function(){

console.log("n--->>nresult:",_data);

pages(_data);

});

});

req.write(content);

req.end();

function pages(datas) {

res.send(datas);//返回页面数据,闭包

}

最后

以上就是辛勤菠萝最近收集整理的关于nodejs做中间层_nodejs做中间层,向后端取数据的全部内容,更多相关nodejs做中间层_nodejs做中间层内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部