Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
到辅助服务器的Java代理POST请求_Java_Tomcat8_Http Proxy - Fatal编程技术网

到辅助服务器的Java代理POST请求

到辅助服务器的Java代理POST请求,java,tomcat8,http-proxy,Java,Tomcat8,Http Proxy,这是我到目前为止的代码 有效的方法是从原始请求中读取所有表单名称/值。 不起作用的是,新服务器没有收到任何新分配的表单名称/值。基本上,它们似乎不会被传输到辅助服务器 也许有一种更简单的方法可以做到这一点??我所需要的只是从新服务器触发一个特定的表单字段,并重定向到一个子服务器,该子服务器将处理请求,并通过主服务器将结果传递回客户端(代理) 我最终设法让它使用以下代码。我希望这能帮助别人 MultipartEntityBuilder mb = null; org.apache.http.Htt

这是我到目前为止的代码

有效的方法是从原始请求中读取所有表单名称/值。 不起作用的是,新服务器没有收到任何新分配的表单名称/值。基本上,它们似乎不会被传输到辅助服务器

也许有一种更简单的方法可以做到这一点??我所需要的只是从新服务器触发一个特定的表单字段,并重定向到一个子服务器,该子服务器将处理请求,并通过主服务器将结果传递回客户端(代理)


我最终设法让它使用以下代码。我希望这能帮助别人

MultipartEntityBuilder mb = null; 
org.apache.http.HttpEntity entity =null;
String value = String.format("https://%s.myotherserver.com%s", "sub1", request.getRequestURI());

mb = MultipartEntityBuilder.create();
mb.addTextBody("noproxy", "true");
mb.addTextBody("text", request.getParameter("text"));
mb.addTextBody("email", request.getParameter("email"));
mb.addBinaryBody("audio", new File(inputAudioFilename));

entity = mb.build();
URLConnection conn = new URL(urlStr[i]).openConnection();
conn.setDoOutput(true);
conn.addRequestProperty(entity.getContentType().getName(), entity.getContentType().getValue());
conn.addRequestProperty("Content-Length", String.valueOf(entity.getContentLength()));
OutputStream fout = conn.getOutputStream();
entity.writeTo(fout);//write multi part data...
fout.flush();
fout.close();
OutputStream output = response.getOutputStream();
output.flush();
                    ByteStreams.copy(conn.getInputStream(),response.getOutputStream());

conn.getInputStream().close();
MultipartEntityBuilder mb = null; 
org.apache.http.HttpEntity entity =null;
String value = String.format("https://%s.myotherserver.com%s", "sub1", request.getRequestURI());

mb = MultipartEntityBuilder.create();
mb.addTextBody("noproxy", "true");
mb.addTextBody("text", request.getParameter("text"));
mb.addTextBody("email", request.getParameter("email"));
mb.addBinaryBody("audio", new File(inputAudioFilename));

entity = mb.build();
URLConnection conn = new URL(urlStr[i]).openConnection();
conn.setDoOutput(true);
conn.addRequestProperty(entity.getContentType().getName(), entity.getContentType().getValue());
conn.addRequestProperty("Content-Length", String.valueOf(entity.getContentLength()));
OutputStream fout = conn.getOutputStream();
entity.writeTo(fout);//write multi part data...
fout.flush();
fout.close();
OutputStream output = response.getOutputStream();
output.flush();
                    ByteStreams.copy(conn.getInputStream(),response.getOutputStream());

conn.getInputStream().close();