支持post,get,delete,get,文件上传相关的也测试过 var http=require(“http”); var url=require(“url”);
var proxyServer=function(request,response,postData){ var options = { host:“10.1.33.202”, //远程ip port: 60001, //远程端口 path: request.url, //path method: request.method, headers: request.headers };
var proxy = http.request(options, function(res){
res.setEncoding('utf8');
response.writeHead(res.statusCode, res.headers);
res.on('data', function(chunk){
response.write(chunk);
});
res.on('end',function(){
console.log("end");
response.end();
});
});
proxy.on('error', function(e){
console.log(e);
});
proxy.write(postData);
proxy.end();
}
var httpServer=http.createServer(function(request,response){ var postData=""; request.setEncoding(‘utf-8’); request.addListener(“data”, function(postDataChunk){ postData += postDataChunk; });
request.addListener("end", function(){
proxyServer(request,response,postData);
});
});
httpServer.listen(8005,“127.0.0.1”, function (){ console.log(“开始监听”+httpServer.address().port+"…"); });
写错了,支持post,get,delete,put