首页 > 解决方案 > Vertx HttpProxy 正在“丢失” Http Request 参数

问题描述

我使用 Vertx HttpProxy 作为反向代理,其“来源”是我将表单数据发布到的地址。出于某种原因,我的表单数据没有到达原点。

我的代码相当简单。我通过此代理从以下 HTML 发送请求:

    <form action="/meeting" method="POST">
        <input style="font-size: 20px;" id="mainparam" name="mainparam" />
        <button type="submit" style="font-family: 'Arbutus Slab', serif;">
            <b style="font-family: 'Arbutus Slab', serif; font-size: 20px;">Join&nbsp; Meeting</b>
        </button>
    </form>

我的代理设置代码,因为它在一个垂直的 start() 函数中工作,如下:

@Override
public void start() throws Exception
{
   HttpServerOptions options = new HttpServerOptions();
   HttpClientOptions clientopt = new HttpClientOptions();
  
   options.setMaxHeaderSize(6000);
   options.setMaxInitialLineLength(100000);
   options.setTcpKeepAlive(true);
  
   clientopt.setMaxHeaderSize(6000);
   clientopt.setMaxInitialLineLength(100000);
   clientopt.setTcpKeepAlive(true);
  
   HttpClient client = vertx.createHttpClient(clientopt);
  
   HttpProxy proxy = HttpProxy.createProxy(client);
  
   proxy.origin(8080,"localhost");
  
   HttpServer server = vertx.createHttpServer(options);
  
   server.requestHandler(proxy);
  
   server.listen(8010,result->{
      if(result.succeeded())
         System.out.println(3,"Proxy Server has started!");
      else if(result.failed())
         System.out.println("Proxy Server start FAILED. Reason: "+result.cause());
  });
}

该页面提交名为“mainparam”的输入框的内容 我的源服务器(与侦听服务器位于不同端口的本地主机)应该能够获取名为“mainparam”的参数的内容。

我的源服务器使用 servlet 来处理请求。在我的 doPost() 方法中,我收到一个 HttpServletRequest 对象,该对象使用以下方法获取参数:

String mainparam = req.getParameter("mainparam");

当我在浏览器上直接访问服务器时,当我调用 getParameter() 时,我的 mainparam 字符串就是我在网页输入框中输入的任何内容。

当我通过代理从浏览器访问服务器时,getParameter() 返回 null。

为了阻止我的代理删除我的参数,我需要做一些设置或配置吗?是什么导致我的代理在通过它发布时丢失了我的参数?

添加信息:

我一直在 HttpProxy 实现类上运行调试会话,以确定一旦请求通过代理,参数会发生什么。我一直在检查传递给 HttpProxyImpl 的 handleProxyRequest() 方法的 HttpServerRequest 对象的内容。

我发现在 HttpServerRequest 对象中有一个名为“params”的属性,我假设它应该包含请求参数。我相信 params 是一个 MultiMap。无论我在 POSTing html 文件中放入的参数类型和数量如何,params 属性始终为空。

我正在继续检查代码,但在我看来,参数似乎没有从 HTTP 请求传输到 HttpProxy 的参数列表中。这意味着 Vert.x 的 HttpProxy 实现中有一个严重的错误。

如果我错了,请有人纠正我,但到目前为止,我似乎发现了一个限制当前 HttpProxy 实现可用性的错误。

标签: javareverse-proxyvert.x

解决方案


推荐阅读