How to resolve HTTP error 414 "Request URI too long"?

I developed a PHP web application. I give the user the ability to update several problems at once. However, sometimes the user encounters this error. Is there a way to increase the length of the url in apache?

+79
May 23 '10 at 11:50
source share
6 answers

In Apache, a constraint is a custom LimitRequestLine value. Change this value to something larger than its default value of 8190 if you want to support a longer request URI. The value is in / etc / apache 2 / apache2.conf. If not, add a new line ( LimitRequestLine 10000 ) to AccessFileName .htaccess .

However, note that if you really use this limit, you are likely to abuse GET for starters. You should use POST to transmit such data - especially since you even acknowledge that you use it to update values. If you check the link above, you will notice that Apache even says: "Under normal circumstances, the value should not change from the default."

+133
May 23 '10 at 11:55
source

Based on John's response, I changed the GET request to a POST request. It works without changing the server configuration. So I went to see how to implement this. The following pages were helpful:

jQuery Example AJAX POST with PHP (Note the sanitation note) and

http://www.openjs.com/articles/ajax_xmlhttp_using_post.php

Basically the difference is that the GET request has the URL and parameters on the same line and then sends null:

 http.open("GET", url+"?"+params, true); http.send(null); 

whereas a POST request sends the URL and parameters to separate commands:

 http.open("POST", url, true); http.send(params); 

Here is a working example:

ajaxPOST.html:

 <html> <head> <script type="text/javascript"> function ajaxPOSTTest() { try { // Opera 8.0+, Firefox, Safari ajaxPOSTTestRequest = new XMLHttpRequest(); } catch (e) { // Internet Explorer Browsers try { ajaxPOSTTestRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajaxPOSTTestRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { // Something went wrong alert("Your browser broke!"); return false; } } } ajaxPOSTTestRequest.onreadystatechange = ajaxCalled_POSTTest; var url = "ajaxPOST.php"; var params = "lorem=ipsum&name=binny"; ajaxPOSTTestRequest.open("POST", url, true); ajaxPOSTTestRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxPOSTTestRequest.send(params); } //Create a function that will receive data sent from the server function ajaxCalled_POSTTest() { if (ajaxPOSTTestRequest.readyState == 4) { document.getElementById("output").innerHTML = ajaxPOSTTestRequest.responseText; } } </script> </head> <body> <button onclick="ajaxPOSTTest()">ajax POST Test</button> <div id="output"></div> </body> </html> 

ajaxPOST.php:

 <?php $lorem=$_POST['lorem']; print $lorem.'<br>'; ?> 

I just sent over 12,000 characters without any problems.

+11
Apr 30 '14 at 3:30
source

I got this error after using $ .getJSON () from jQuery. I just changed the message:

 data = getDataObjectByForm(form); var jqxhr = $.post(url, data, function(){}, 'json') .done(function (response) { if (response instanceof Object) var json = response; else var json = $.parseJSON(response); // console.log(response); // console.log(json); jsonToDom(json); if (json.reload != undefined && json.reload) location.reload(); $("body").delay(1000).css("cursor", "default"); }) .fail(function (jqxhr, textStatus, error) { var err = textStatus + ", " + error; console.log("Request Failed: " + err); alert("Fehler!"); }); 
+2
Nov 16 '16 at 11:20
source

Excerpt from RFC 2616: Hypertext Transfer Protocol - HTTP / 1.1 :

The POST method is used to request that the source server accept the object included in the request as a new subordinate resource identified by the Request-URI in the query string. POST is designed so that a unified method can perform the following functions:

  • Annotation of existing resources;
  • Placing a message on a bulletin board, in a news group, mailing list or similar group of articles;
  • Providing a data block, such as the result of submitting the form, to the data processing process ;
  • Extending the database using the add operation.
+1
May 23 '10 at 12:06 a.m.
source

See this answer:

https://pt.stackoverflow.com/questions/350227/yii2-como-ordenar-o-gridview-em-um-formul%C3%A1rio-post-sem-perder-os-filtros-usa

In response, you will reduce the size of the URL to use the GET method.

0
Dec 18 '18 at 11:35
source

I have a simple workaround.

Suppose your URI has a stringdata string that is too long. You can simply split it into several parts depending on the limits of your server. Then send the first one, in my case, write the file. Then send the following to add to the previously added data.

-one
04 Sep
source



All Articles