• GET Post 请求的 URL 总长度


    http://vontall.blogbus.com/logs/4831888.html

     

    昨天把写的那篇《什么时候用GET?什么时候用POST?》给转到了phpx,结果有网友置疑,认为“GET最多不可超过255个字符”。虽说这篇文章是从著名的《PHP & MySQL Web数据库应用开发指南》上摘下来的更让我信任,本着钻研的精神我还是在网上进行了一翻考证。

    还真找到了最权威的资料:

    这个是微软官方的解释:http://support.microsoft.com/default.aspx?scid=kb;EN-US;q208427
    长度是2083字节,路径的最大长度是2048字节, post和get都是,这已经远大于传说的256了。

    SUMMARY

    loadTOCNode(1, 'summary');

    Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters. Internet Explorer also has a maximum path length of 2,048 characters. This limit applies to both POST request and GET request URLs. 

    If you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path.

    However, the POST method is not limited by the size of the URL for submitting name/value pairs. These pairs are transferred in the header and not in the URL. 

    RFC 2616, "Hypertext Transfer Protocol -- HTTP/1.1," does not specify any requirement for URL length.

    REFERENCES

    loadTOCNode(1, 'references'); For a further breakdown of the components, see the Wininet header file. 

    For more information, see "General Syntax," section 3.2.1 of RFC 2616, "Hypertext Transfer Protocol -- HTTP/1.1," at the following Internet Society Web site:ftp://ftp.isi.edu/in-notes/rfc2616.txt
    下面的文章取自RFC更加的权威了http://classicasp.aspfaq.com/forms/what-is-the-limit-on-querystring/get/url-parameters.html

    What is the limit on QueryString / GET / URL parameters?

    RFC 2068 states:
      Servers should be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations may not properly support these lengths.
    The spec for URL length does not dictate a minimum or maximum URL length, but implementation varies by browser. On Windows: Opera supports ~4050 characters, IE 4.0+ supports exactly 2083 characters, Netscape 3 -> 4.78 support up to 8192 characters before causing errors on shut-down, and Netscape 6 supports ~2000 before causing errors on start-up. 

    Note that there is no limit on the number of parameters you can stuff into a URL, but only on the length it can aggregate to. 

    Keep in mind that the number of characters will be significantly reduced if you have special characters (e.g. spaces) that need to be URLEncoded (e.g. converted to the sequence '%20'). For every space, you reduce the size allowed in the remainder of the URL by 2 characters - and this holds true for many other special characters that you may encode before sending the URL to the client. 

    Keep in mind, also, that the SGML spec declares that a URL as an attribute value (e.g. ) cannot be more than 1024 characters. Similarly, the GET request is stored in the server variable QUERY_STRING, which can have similar limitations in certain scenarios. 

    If you are hitting a limit on length, you should consider using POST instead of GET. POST does not have such low limits on the size of name/value pairs, because the data is sent in the header, not in the URL. The limit on POST size, by default, is 2 MB on IIS 4.0 and 128 KB on IIS 5.0. POST is also a little more secure than GET -- it's tougher (though not impossible) to tinker with the values of POSTed variables, than values sitting in the querystring. 

    See Article #2223 for more information on using POST to overcome limitations on length.

    原来HTTP协议本身未指定任何对URL长度要求。它只是建议不要超过255个字符,因为有些很老的客户端或者代理只能接收小于255个字符的URL,服务器本身不限制URL的长度。但是客户端或者代理通常都会限制URL的长度,IE本身对GET请求的URL总长度限制是2048字符, 减去实际路径中的字符数就是允许参数长度,而其它几个浏览器支持得甚至更长。浏览器的版本也不必过地担心,还有几人在用IE4.0以前的“史前”版本呢?

     ========各浏览器HTTP Get请求URL最大长度==========

    各浏览器HTTP Get请求URL最大长度并不相同,几类常用浏览器最大长度及超过最大长度后提交情况如下:

    IE6.0 :url最大长度2083个字符,超过最大长度后无法提交。
    IE7.0 :url最大长度2083个字符,超过最大长度后仍然能提交,但是只能传过去2083个字符。
    firefox 3.0.3 :url最大长度7764个字符,超过最大长度后无法提交。
    Opera 9.52 :url最大长度7648个字符,超过最大长度后无法提交。
    Google Chrome 2.0.168 :url最大长度7713个字符,超过最大长度后无法提交。

    =========HTTP GET请求的URL长度限制===========

    受客户端浏览器和服务器两方面的限制:

    由于环境所限,我客户端ie7,服务器apache2.2.11。

    <?php
    $i=1000;
    do{
    $i+=1000;
    $url = str_pad("http://localhost/?",$i,'x');
    }while(file_get_contents($url));
    echo $i;
    ?>
    发现9000的时候终止了。
    <?php
    $i=8000;
    do{
    $i+=100;
    $url = str_pad("http://localhost/?",$i,'x');
    }while(file_get_contents($url));
    echo $i;
    ?>
    发现8200的时候终止了。
    <?php
    $i=8100;
    do{
    $i+=10;
    $url = str_pad("http://localhost/?",$i,'x');
    }while(file_get_contents($url));
    echo $i;
    ?>
    发现8200的时候终止了。
    <?php
    $i=8190;
    do{
    $i++;
    $url = str_pad("http://localhost/?",$i,'x');
    }while(file_get_contents($url));
    echo $i;
    ?>
    发现8194的时候终止了。

    服务器支持8k多一点。
    ie经过测试,支持2k。

  • 相关阅读:
    20169204,EXP 3:Java object
    20169204,EXP 2:Java object
    20169204,exp1:Familiar with the Java development environment(Linux+IDEA)
    20169204 2016-2017-2 <Mobbile Platform Development and Practice> Learning Summary, Seventh Week
    第一次使用MarkDown写博客
    理解IOC
    .net与技术经理面谈时经常被提问到的相关技术点
    缓存二、HttpRuntime.Cache用法
    缓存一、Asp.net页面缓存
    一次提交涉及两个数据库处理
  • 原文地址:https://www.cnblogs.com/backpacker/p/2262379.html
Copyright © 2020-2023  润新知