JPr*_*Pro 95 php apache http-status-codes
我开发了一个PHP Web应用程序.我给了用户一个选项,可以一次更新多个问题.在这样做时,有时用户遇到此错误.有没有办法增加apache中URL的长度?
Joh*_*lla 157
在Apache下,限制是可配置的值LimitRequestLine.如果要支持更长的请求URI,请将此值更改为大于其默认值8190的值.该值位于/etc/apache2/apache2.conf中.如果没有,请在下面添加一个新行(LimitRequestLine 10000)AccessFileName .htaccess.
但请注意,如果您实际上遇到此限制,则可能GET会开始滥用.您应该使用POST传输此类数据 - 特别是因为您甚至承认您正在使用它来更新值.如果你查看上面的链接,你会注意到Apache甚至说"在正常情况下,不应该从默认值更改值".
atm*_*ino 14
根据John的回答,我将GET请求更改为POST请求.它可以工作,而无需更改服务器配置.所以我去了解如何实现这一点.以下页面很有帮助:
使用PHP的jQuery Ajax POST示例 (请注意sanitize发布的数据备注)和
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
基本上,区别在于GET请求在一个字符串中有url和参数,然后发送null:
http.open("GET", url+"?"+params, true);
http.send(null);
Run Code Online (Sandbox Code Playgroud)
而POST请求在单独的命令中发送url和参数:
http.open("POST", url, true);
http.send(params);
Run Code Online (Sandbox Code Playgroud)
这是一个工作示例:
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>
Run Code Online (Sandbox Code Playgroud)
ajaxPOST.php:
<?php
$lorem=$_POST['lorem'];
print $lorem.'<br>';
?>
Run Code Online (Sandbox Code Playgroud)
我刚刚发送了12,000多个字符而没有任何问题.
小智 6
我有一个简单的解决方法。
假设您的 URI 有一个stringdata太长的字符串。您可以根据服务器的限制将其简单地分成多个部分。然后提交第一个,在我的情况下写一个文件。然后提交下一个附加到先前添加的数据。
| 归档时间: |
|
| 查看次数: |
260615 次 |
| 最近记录: |