Java 提交的表单数据在url中可见,尽管使用了method=post
我在提交表单数据(即textarea)时使用了POST作为方法,但它在URL中仍然可见。这导致在NetBeans上运行的web应用程序出现以下错误:Java 提交的表单数据在url中可见,尽管使用了method=post,java,jsp,http,url,post,Java,Jsp,Http,Url,Post,我在提交表单数据(即textarea)时使用了POST作为方法,但它在URL中仍然可见。这导致在NetBeans上运行的web应用程序出现以下错误: Aug 30, 2016 11:25:02 AM org.apache.coyote.http11.AbstractHttp11Processor process INFO: Error parsing HTTP request header Note: further occurrences of HTTP header parsing err
Aug 30, 2016 11:25:02 AM org.apache.coyote.http11.AbstractHttp11Processor process
INFO: Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Request header is too large
at org.apache.coyote.http11.InternalAprInputBuffer.fill(InternalAprInputBuffer.java:574)
at org.apache.coyote.http11.InternalAprInputBuffer.parseRequestLine(InternalAprInputBuffer.java:217)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:996)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:722)
这是由于从我收集的URL中超出了限制而导致的
index.jsp代码片段:
form id="maryWebClient" action="preprocess" method="POST">
URL obj=new URL("http://..../process?INPUT_TEXT="+"\""+ URLEncoder.encode(sent)+"\""+ "&INPUT_TYPE=TEXT&OUTPUT_TYPE=REALISED_DURATIONS&LOCALE=hi_IN&OUTPUT_TYPE_PARAMS=phone+stressed+accented");
BufferedReader bfr=new BufferedReader(new InputStreamReader(obj.openStream(),"utf8"));
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
稍后,我还尝试使用Preprocessor.java中的以下代码将该方法显式设置为POST,通过使用index.jsp代码片段中的urlPatterns向其发送数据:
form id="maryWebClient" action="preprocess" method="POST">
URL obj=new URL("http://..../process?INPUT_TEXT="+"\""+ URLEncoder.encode(sent)+"\""+ "&INPUT_TYPE=TEXT&OUTPUT_TYPE=REALISED_DURATIONS&LOCALE=hi_IN&OUTPUT_TYPE_PARAMS=phone+stressed+accented");
BufferedReader bfr=new BufferedReader(new InputStreamReader(obj.openStream(),"utf8"));
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
在GET请求中,参数作为URL的一部分发送 在POST请求中,参数作为请求的主体发送,在头之后 要使用HttpURLConnection进行POST,需要在打开连接后将参数写入连接 这段代码应该让您开始:
String urlParameters = "param1=a¶m2=b¶m3=c";
byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;
String request = "http://example.com/index.php";
URL url = new URL( request );
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
conn.setDoOutput( true );
conn.setInstanceFollowRedirects( false );
conn.setRequestMethod( "POST" );
conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "charset", "utf-8");
conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
conn.setUseCaches( false );
try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
wr.write( postData );
}
在GET请求中,参数作为URL的一部分发送 在POST请求中,参数作为请求的主体发送,在头之后 要使用HttpURLConnection进行POST,需要在打开连接后将参数写入连接 这段代码应该让您开始:
String urlParameters = "param1=a¶m2=b¶m3=c";
byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;
String request = "http://example.com/index.php";
URL url = new URL( request );
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
conn.setDoOutput( true );
conn.setInstanceFollowRedirects( false );
conn.setRequestMethod( "POST" );
conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "charset", "utf-8");
conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
conn.setUseCaches( false );
try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
wr.write( postData );
}
下面的方法解决了我的问题。我使用ajax调用发送post请求
var postData=$("#maryWebClient").serializeArray();
$.ajax({
url: "preprocess",
context:this,
type:"POST",
dataType:"json",
data:postData,
success: function(response){
$("#INPUT_TEXT").val(response["x"]);
$("#INPUT_TEXT2").val(response["y"]);
},
error: function(errorData){alert(errorData);}
});
下面的方法解决了我的问题。我使用ajax调用发送post请求
var postData=$("#maryWebClient").serializeArray();
$.ajax({
url: "preprocess",
context:this,
type:"POST",
dataType:"json",
data:postData,
success: function(response){
$("#INPUT_TEXT").val(response["x"]);
$("#INPUT_TEXT2").val(response["y"]);
},
error: function(errorData){alert(errorData);}
});
谢谢你的回答@Jenkin。我确实尝试过类似于此链接中提到的内容。但这对我不起作用。我也尝试了你的代码,但得到了同样的错误。我不明白为什么jsp/HTML表单帖子会通过servlet路由?@可怕的是,我专注于如何使用java URL类发送帖子数据,rest方法取决于OP的观点,我无法理解与投票相关的问题谢谢你的回答@Jenkin。我确实尝试过类似于此链接中提到的内容。但这对我不起作用。我也尝试了你的代码,但得到了相同的错误。我不明白为什么jsp/HTML表单帖子会通过servlet路由?@我当时关注的是如何使用java URL类发送帖子数据,rest方法取决于OP的观点,我无法理解这一点