Express.js代理发布请求

我审查了节点https://github.com/mikeal/request的请求模块但是不知道如何代理POST请求到远程服务器,例如

app.post('/items', function(req, res){ var options = { host: 'https://remotedomain.com', path: '/api/items/, port: 80 }; var ret = res; http.get(options, function(res){ var data = ''; res.on('data', function(chunk){ data += chunk; }); res.on('end', function(){ var obj = JSON.parse(data); ret.json({obj: obj}); console.log('end'); }); }); }); 

除非我从你的问题中遗漏了一些东西,否则你可以做一个简单的post,然后对响应数据做一些事情:

 var request = require('request'); app.post('/items', function(req, res){ request.post('https://remotedomain.com/api/items', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body); // Print the body of the response. If it's not there, check the response obj //do all your magical stuff here } })