【问题标题】:error on Ajax GET request with a lots of parameters带有大量参数的 Ajax GET 请求错误
【发布时间】:2011-06-17 07:15:29
【问题描述】:

发送 URL 长度约为 4950 个字符的请求。

获取以下 XMLHTTPRequest.ResponseText:

ERROR
The requested URL could not be retrieved

While trying to retrieve the URL: ##my long url##
The following error was encountered:
Invalid URL
Some aspect of the requested URL is incorrect. Possible problems:
Missing or incorrect access protocol (should be `http://'' or similar)
Missing hostname
Illegal double-escape in the URL-Path
Illegal character in hostname; underscores are not allowed
Your cache administrator is webmaster. 

但是当我在浏览器中输入相同的 url 时,它工作得很好。我检查了可能的错误(在响应文本中列出) - 一切正常。

当参数的数量小于~200 时,脚本会起作用,因此线索必须在一定范围内。另一方面,apache 或 php 或 js 中没有任何设置。

任何建议或我应该在哪里寻找解决方案(一些额外的配置或其他)?

【问题讨论】:

    标签: javascript jquery ajax


    【解决方案1】:

    发送 URL 长度约为 4950 个字符的请求。

    无论如何,这对于 Internet Explorer 来说太过分了。也可能适用于 Opera,IIRC 的 GET 请求限制为 4096 字节。

    你应该使用 POST 来处理这么多的数据。

    Maximum URL length is 2,083 characters in Internet Explorer

    【讨论】:

    • 谢谢你,佩卡。仅作记录:它在 Chrome 中也不起作用 =)
    • POST 是个好主意,但它不适用于跨域请求,JSONP 仅适用于 GET
    【解决方案2】:

    如果 URL 超过大约 4000 个字符(请求行为 capped to 8190 bytes),则 Apache 将回复 413 Entity Too Large

    使用LimitRequestLine 指令将无济于事,如果您绝对想发送大型 GET 请求,则必须使用 -D DEFAULT_LIMIT_REQUEST_LINE=some huge value 重新编译 Apache。

    编辑: 关于 ~4000 字符上限的一些想法:8190 看起来很像 8192 with two bytes reserved for the string terminator,因此 Apache 很有可能使用 UCS-2 或类似的存储请求行,因为DEFAULT_LIMIT_REQUEST_LINE 以字节表示,而不是字符。

    这将为每个请求行提供 4095 个字符的上限,即最大 URL 长度为 4079 个字符(考虑到初始的 GET 和最后的 CR/LF 对),这是有道理的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多