Nodejs 请求转发代理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nodejs 请求转发代理相关的知识,希望对你有一定的参考价值。
var sendPromise = function (res, callback) { var options = { hostname: settings.Ip, port: settings.Port, path: ‘‘, method: ‘GET‘, headers: res.req.headers }; options.path = res.req.originalUrl; options.method = res.req.method; var body = res.req.body; var request = http.request(options, function (response) { var result = ‘‘; response.setEncoding(‘utf8‘); response.on(‘data‘, function (chunk) { result += chunk; }); response.on(‘end‘, function () { callback(null, result); }); }); request.on(‘error‘, function (e) { callback(‘path:‘ + options.path + ‘;‘ + e, null); }); if (body && options.method == ‘POST‘) { var postBody = {}; for (var k of Object.keys(body)) { postBody[k] = body[k]; } request.write(postBody); } request.end(); }
以上是关于Nodejs 请求转发代理的主要内容,如果未能解决你的问题,请参考以下文章