这是我正在使用的模块版本:
$ npm list -g | grep proxy
├─┬ http-proxy@0.10.0
Web服务调用我的机器,我的任务是根据请求主体的内容将请求代理到另一个URL和主机,并附加一个查询参数:
var http = require('http'),
httpProxy = require('http-proxy')
form2json = require('form2json');
httpProxy.createServer(function (req, res, proxy) {
// my custom logic
var fullBody = '';
req.on('data', function(chunk) {
// append the current chunk of data to the fullBody variable
fullBody += chunk.toString();
});
req.on('end', function() {
var jsonBody = form2json.decode(fullBody);
var payload = JSON.parse(jsonBody.payload);
req.url = '/my_couch_db/_design/ddoc_name/_update/my_handler?id="' + payload.id + '"';
// standard proxy stuff
proxy.proxyRequest(req, res, {
changeOrigin: true,
host: 'my.cloudant.com',
port: 443,
https: true
});
});
}).listen(8080);
但我一直遇到像An error has occurred: {"code":"ECONNRESET"}
任何人都知道需要在这里修复什么?
答案 0 :(得分:8)
这对我有用:
var httpProxy = require('http-proxy');
var options = {
changeOrigin: true,
target: {
https: true
}
}
httpProxy.createServer(443, 'www.google.com', options).listen(8001);
答案 1 :(得分:2)
将端口3000
上的所有请求转发至https://google.com
:
const https = require('https')
const httpProxy = require('http-proxy')
httpProxy.createProxyServer({
target: 'https://google.com',
agent: https.globalAgent,
headers: {
host: 'google.com'
}
}).listen(3000)
受https://github.com/nodejitsu/node-http-proxy/blob/master/examples/http/proxy-http-to-https.js启发的示例。
答案 2 :(得分:0)
经过一些反复试验,这对我有用:
03-324-27216|14, , ,"1,=,14',0"",X,3.500""",14.000,,49, ,, ,3.500, ,MF,AU,210,AS,M,,0, ,05-01-15, ,,
03-362-50502|14,24543, ,"1,=,21',6"",X,3.625""",21.000,,77, ,, ,3.625, ,BF,GP,212, ,, ,, , ,