我想修改请求数据查询(不是标题)
如果查询=" a1 = b1& a2 = b2& a3 = b3"然后
我发送查询=" a1 = c1& a2 = c2& a3 = c3"到proxy.web
如何修改?
var server = http.createServer(function (req, res) {
var reqChunks = [];
var msgchunk = '';
req.on('data', function(chunk) {
reqChunks.push(chunk);
});
req.on('end',function(){
});
proxy.web(req, res, {target: req.url, prependPath: false});
答案 0 :(得分:0)
您可以使用以下代码:
var http = require('http');
const url = require('url');
const querystring = require('querystring');
http.createServer(function (req, res) {
const {query} = url.parse(req.url, true);
query.a1 = 'c1';
query.a2 = 'c2';
req.url = `/?${querystring.stringify(query)}`
var reqChunks = [];
var msgchunk = '';
req.on('data', function(chunk) {
reqChunks.push(chunk);
});
req.on('end',function(){
});
proxy.web(req, res, {target: req.url, prependPath: false});
}).listen(8080);