Proxy 禁止节点HTTP代理403 Post请求

Proxy 禁止节点HTTP代理403 Post请求,proxy,Proxy,我使用节点http代理将我的请求从端口sample.com:80代理到端口sample.com:8080,示例如下: var httpProxy = require('http-proxy'); httpProxy.createServer(8080, 'localhost').listen(80); http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' });

我使用节点http代理将我的请求从端口
sample.com:80
代理到端口
sample.com:8080
,示例如下:

var httpProxy = require('http-proxy');

httpProxy.createServer(8080, 'localhost').listen(80);

http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9000);
当我在
sample.com:80
上发布时:curl,我得到
403禁止响应
。但是当我使用GET执行curl时,
301永久重定向
。我的问题是:

是否可以使POST和GET的行为相同,总是返回200个状态码而不是403或301


谢谢

在做了一些研究之后,我为自己的问题找到了一个解决方案:请注意,放置固定端口和ip是错误的编码,它们应该在配置文件或命令行参数中
var fmt = require('fmt');
var httpProxy = require('http-proxy');

fmt.sep();
console.log();
fmt.title("\033[1;36mPROXY SERVER STARTED\033[0m");
console.log();
fmt.field("\033[1;34mPROXY PORT\033[0m", 80);
fmt.field("\033[1;34mTARGET PORT\033[0m", 8080);
fmt.field("\033[1;34mTARGET ADDRESS\033[0m", '127.0.0.1');

var server = httpProxy.createServer(function(req, res, proxy)
{
    proxy.proxyRequest(req, res, { host: '127.0.0.1', port: 8080, buffer: httpProxy.buffer(req) });

    var reqBody = '';

    req.on('data', function(chunk)
    {
        reqBody += chunk;
    });

    req.on('end', function()
    {
        console.log();
        fmt.sep();
        console.log();
        fmt.title("\033[1;36mREQUEST FROM SHARED CLOUD\033[0m");
        console.log();
        fmt.dump(req.connection.remoteAddress, "\033[1;35mADDRESS\033[0m");
        console.log();
        fmt.msg("\033[1;35mHEADERS\033[0m :");
        fmt.dump(req.headers);
        console.log();
        fmt.msg("\033[1;35mBODY\033[0m :");
        fmt.dump(reqBody);
        console.log();
    });
});

server.proxy.on('proxyError', function(err, req, res)
{
    fmt.title("\033[1;36mPROXY STATUS\033[0m");
    console.log();
    fmt.dump('failed to proxy on port ' + 8080, "\033[1;31mERROR\033[0m");
    res.end();
});

server.proxy.on('end', function()
{
    fmt.title("\033[1;36mPROXY STATUS\033[0m");
    console.log();
    fmt.dump('request was proxied successfully', "\033[1;33mSTATUS\033[0m");
});

server.listen(80);