coder0007 coder0007 - 2 months ago 25
HTTP Question

Submitted form data visible in url despite using method=post

I have used POST as the method when submitting form data (namely textarea), but it is still visible in the URL. This is causing the following error in my web application (running on NetBeans):

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)


This is caused due to the limit exceeded in the URL (from what I have gathered).

index.jsp (code fragment):

form id="maryWebClient" action="preprocess" method="POST">


I have also later tried to explicitly set the method as POST by using the following code in Preprocessor.java, to which data is being sent by using urlPatterns from index.jsp (code fragment):

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");

Answer

The following approach solved my problem. I have used ajax call to send a post request.

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);}
 });