Express.js 使用 http-proxy 进行代理,如果代理post请求时,第三方服务器,无法获取post的参数,以及在进行代理时,过大概20秒之后再进行转发
var express = require(‘express’); var router = express.Router(); var httpProxy = require(‘http-proxy’);
//新建一个代理Proxy server 对象 var proxy = httpProxy.createProxyServer({});
proxy.on(‘proxyReq’, function (proxyReq, req, res, options) { proxyReq.body = req.body; console.log("-----proxyReq--------"); });
router.post(’/gcl/vri/versionScan’, function (req, res, next) { console.log(req.body.name); console.log(req.body.password); console.log("----/gcl/vri/versionScan–"); proxy.web(req, res, {target: ‘http://192.168.11.150:8161’}); });
做过这方面的麻烦看看,特急!!!