119

我开发了一个 PHP 网络应用程序。我为用户提供了一次更新多个问题的选项。这样做时,有时用户会遇到此错误。有什么方法可以增加 apache 中 URL 的长度?

4

5 回答 5

183

在 Apache 下,限制是一个可配置的值,LimitRequestLine. 如果您想支持更长的请求 URI,请将此值更改为大于其默认值 8190 的值。该值在/etc/apache2/apache2.conf中。如果没有,请在 下添加新行 ( LimitRequestLine 10000) AccessFileName .htaccess

但是,请注意,如果您实际上遇到了这个限制,那么您可能GET一开始就滥用了。您应该使用它POST来传输此类数据——尤其是因为您甚至承认您正在使用它来更新值。如果您检查上面的链接,您会注意到 Apache 甚至说“在正常情况下,不应更改默认值”。

于 2010-05-23T11:55:51.217 回答
18

根据约翰的回答,我将 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);

而 POST 请求在单独的命令中发送 url 和参数:

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

这是一个工作示例:

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>';

?>

我刚刚发送了超过 12,000 个字符,没有任何问题。

于 2014-04-30T03:30:10.420 回答
7

我有一个简单的解决方法。

stringdata假设您的 URI 有一个太长的字符串。您可以根据服务器的限制将其简单地分解为多个部分。然后提交第一个,在我的情况下写一个文件。然后提交下一个以附加到先前添加的数据。

于 2012-09-04T14:36:53.947 回答
3

使用 JQuery 中的 $.getJSON() 后出现此错误。我刚改发帖:

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!");
    });
于 2016-11-16T11:20:04.390 回答
1

RFC 2616的摘录:超文本传输​​协议——HTTP/1.1

POST方法用于请求源服务器接受请求中包含的实体,作为 Request-Line 中 Request-URI 标识的资源的新下级。POST 旨在允许统一的方法涵盖以下功能:

  • 现有资源的注释;
  • 将消息发布到公告板、新闻组、邮件列表或类似的文章组;
  • 向数据处理进程提供数据块,例如提交表单的结果
  • 通过追加操作扩展数据库。
于 2010-05-23T12:06:28.490 回答