I have developed a PHP web app. I am giving an option to the user to update multiple issues on one go. In doing so, sometimes the user is encountering this error. Is there any way to increase the lenght of URL in apache?
我开发了一个PHP web应用程序。我为用户提供了一次更新多个问题的选项。这样做时,用户有时会遇到这个错误。有没有办法增加apache中的URL权限?
5 个解决方案
#1
129
Under Apache, the limit is a configurable value, LimitRequestLine
. Change this value to something larger than its default of 8190 if you want to support a longer request URI. The value is in /etc/apache2/apache2.conf. If not, add a new line (LimitRequestLine 10000
) under AccessFileName .htaccess
.
在Apache下,限制是一个可配置的值,LimitRequestLine。如果希望支持更长的请求URI,请将该值更改为大于其默认值8190的值。该值在/etc/apache2/apache2.conf中。如果没有,在AccessFileName .htaccess下添加一条新行(LimitRequestLine 10000)。
However, note that if you're actually running into this limit, you are probably abusing GET
to begin with. You should use POST
to transmit this sort of data -- especially since you even concede that you're using it to update values. If you check the link above, you'll notice that Apache even says "Under normal conditions, the value should not be changed from the default."
然而,请注意,如果你真的遇到了这个限制,你可能会滥用GET to开头。您应该使用POST来传输这类数据,特别是在您甚至承认使用它来更新值的时候。如果您查看上面的链接,您会注意到Apache甚至说“在正常情况下,值不应该从默认值更改”。
#2
10
Based on John's answer, I changed the GET request to a POST request. It works, without having to change the server configuration. So I went looking how to implement this. The following pages were helpful:
基于John的回答,我将GET请求改为POST请求。它可以工作,无需更改服务器配置。所以我开始研究如何实现这个。以下几页很有帮助:
jQuery Ajax POST example with PHP (Note the sanitize posted data remark) and
jQuery Ajax POST示例使用PHP(注意已发布的数据注释)和
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
Basically, the difference is that the GET request has the url and parameters in one string and then sends null:
基本上,不同之处在于GET请求在一个字符串中包含url和参数,然后发送null:
http.open("GET", url+"?"+params, true);
http.send(null);
whereas the POST request sends the url and the parameters in separate commands:
而POST请求以单独的命令发送url和参数:
http.open("POST", url, true);
http.send(params);
Here is a working example:
这里有一个工作示例:
ajaxPOST.html:
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:
ajaxPOST.php:
<?php
$lorem=$_POST['lorem'];
print $lorem.'<br>';
?>
I just sent over 12,000 characters without any problems.
我刚刚发送了超过12000个字符,没有任何问题。
#3
1
I got this error after using $.getJSON() from JQuery. I just changed to post:
在使用JQuery的$. getjson()之后,我得到了这个错误。我刚换到post:
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!");
});
#4
0
An excerpt from the RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1:
RFC 2616:超文本传输协议——HTTP/1.1:
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
POST方法用于请求源服务器接受请求中包含的实体,作为请求行中的请求- uri标识的资源的新附属。POST的设计目的是让统一的方法覆盖以下功能:
- Annotation of existing resources;
- 注释现有的资源;
- Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
- 向布告栏、新闻组、邮件列表或类似的文章组发布信息;
- Providing a block of data, such as the result of submitting a form, to a data-handling process;
- 提供一组数据,例如提交表单的结果,以及数据处理过程;
- Extending a database through an append operation.
- 通过附加操作扩展数据库。
#5
-2
I have a simple workaround.
我有个简单的办法。
Suppose your URI has a string stringdata
that is too long. You can simply break it into a number of parts depending on the limits of your server. Then submit the first one, in my case to write a file. Then submit the next ones to append to previously added data.
假设您的URI有一个太长的字符串stringdata。根据服务器的限制,您可以简单地将其分解为多个部分。然后提交第一个,在我的情况下写一个文件。然后提交下一个添加到以前添加的数据。
#1
129
Under Apache, the limit is a configurable value, LimitRequestLine
. Change this value to something larger than its default of 8190 if you want to support a longer request URI. The value is in /etc/apache2/apache2.conf. If not, add a new line (LimitRequestLine 10000
) under AccessFileName .htaccess
.
在Apache下,限制是一个可配置的值,LimitRequestLine。如果希望支持更长的请求URI,请将该值更改为大于其默认值8190的值。该值在/etc/apache2/apache2.conf中。如果没有,在AccessFileName .htaccess下添加一条新行(LimitRequestLine 10000)。
However, note that if you're actually running into this limit, you are probably abusing GET
to begin with. You should use POST
to transmit this sort of data -- especially since you even concede that you're using it to update values. If you check the link above, you'll notice that Apache even says "Under normal conditions, the value should not be changed from the default."
然而,请注意,如果你真的遇到了这个限制,你可能会滥用GET to开头。您应该使用POST来传输这类数据,特别是在您甚至承认使用它来更新值的时候。如果您查看上面的链接,您会注意到Apache甚至说“在正常情况下,值不应该从默认值更改”。
#2
10
Based on John's answer, I changed the GET request to a POST request. It works, without having to change the server configuration. So I went looking how to implement this. The following pages were helpful:
基于John的回答,我将GET请求改为POST请求。它可以工作,无需更改服务器配置。所以我开始研究如何实现这个。以下几页很有帮助:
jQuery Ajax POST example with PHP (Note the sanitize posted data remark) and
jQuery Ajax POST示例使用PHP(注意已发布的数据注释)和
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
Basically, the difference is that the GET request has the url and parameters in one string and then sends null:
基本上,不同之处在于GET请求在一个字符串中包含url和参数,然后发送null:
http.open("GET", url+"?"+params, true);
http.send(null);
whereas the POST request sends the url and the parameters in separate commands:
而POST请求以单独的命令发送url和参数:
http.open("POST", url, true);
http.send(params);
Here is a working example:
这里有一个工作示例:
ajaxPOST.html:
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:
ajaxPOST.php:
<?php
$lorem=$_POST['lorem'];
print $lorem.'<br>';
?>
I just sent over 12,000 characters without any problems.
我刚刚发送了超过12000个字符,没有任何问题。
#3
1
I got this error after using $.getJSON() from JQuery. I just changed to post:
在使用JQuery的$. getjson()之后,我得到了这个错误。我刚换到post:
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!");
});
#4
0
An excerpt from the RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1:
RFC 2616:超文本传输协议——HTTP/1.1:
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
POST方法用于请求源服务器接受请求中包含的实体,作为请求行中的请求- uri标识的资源的新附属。POST的设计目的是让统一的方法覆盖以下功能:
- Annotation of existing resources;
- 注释现有的资源;
- Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
- 向布告栏、新闻组、邮件列表或类似的文章组发布信息;
- Providing a block of data, such as the result of submitting a form, to a data-handling process;
- 提供一组数据,例如提交表单的结果,以及数据处理过程;
- Extending a database through an append operation.
- 通过附加操作扩展数据库。
#5
-2
I have a simple workaround.
我有个简单的办法。
Suppose your URI has a string stringdata
that is too long. You can simply break it into a number of parts depending on the limits of your server. Then submit the first one, in my case to write a file. Then submit the next ones to append to previously added data.
假设您的URI有一个太长的字符串stringdata。根据服务器的限制,您可以简单地将其分解为多个部分。然后提交第一个,在我的情况下写一个文件。然后提交下一个添加到以前添加的数据。