关于URL最大长度限制的相关资料查证_php技巧

在开发调试支付宝接口时,突然发现支付宝接口的URL很长,远远大于之前自己印象中的255个字符。赶紧搜索查证了一番,理解如下:

URL不能大于255bytes的说法确实存在,在RFC2616中提到:

复制代码 代码如下:

The HTTP protocol does not place any a priori limit on the length of a URI. Servers MUST be able to handle the URI of any resource they serve, and SHOULD be able to handle URIs of unbounded length if they provide GET-based forms that could generate such URIs. A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle (see section 10.4.15).

Note: Servers ought to be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations might not properly support these lengths.

从上一点也可以看出,255bytes的说法也是为了兼容性考虑。实际上现代浏览器的限制如下:

复制代码 代码如下:

Microsoft Internet Explorer (Browser)
Microsoft states that the maximum length of a URL in Internet Explorer is 2,083 characters, with no more than 2,048 characters in the path portion of the URL. In my tests, attempts to use URLs longer than this produced a clear error message in Internet Explorer.

Firefox (Browser)
After 65,536 characters, the location bar no longer displays the URL in Windows Firefox 1.5.x. However, longer URLs will work. I stopped testing after 100,000 characters.

Safari (Browser)
At least 80,000 characters will work. I stopped testing after 80,000 characters.

Opera (Browser)
At least 190,000 characters will work. I stopped testing after 190,000 characters. Opera 9 for Windows continued to display a fully editable, copyable and pasteable URL in the location bar even at 190,000 characters.

Apache (Server)
My early attempts to measure the maximum URL length in web browsers bumped into a server URL length limit of approximately 4,000 characters, after which Apache produces a “413 Entity Too Large” error. I used the current up to date Apache build found in Red Hat Enterprise Linux 4. The official Apache documentation only mentions an 8,192-byte limit on an individual field in a request.

Microsoft Internet Information Server
The default limit is 16,384 characters (yes, Microsoft's web server accepts longer URLs than Microsoft's web browser). This is configurable.

Perl HTTP::Daemon (Server)
Up to 8,000 bytes will work. Those constructing web application servers with Perl's HTTP::Daemon module will encounter a 16,384 byte limit on the combined size of all HTTP request headers. This does not include POST-method form data, file uploads, etc., but it does include the URL. In practice this resulted in a 413 error when a URL was significantly longer than 8,000 characters. This limitation can be easily removed. Look for all occurrences of 16×1024 in Daemon.pm and replace them with a larger value. Of course, this does increase your exposure to denial of service attacks.

另外值得注意的是,有文章提到作为<a>的href属性时,URL不能超过1024bytes,这点没有详细查证

综上,URL还是不适合太长,不是不得已,尽量不要通过GET方式提交大量参数,可以考虑用POST方式(大约在2M左右,应该是和服务器及设定有关)。另外这么长的URL在访问和收藏(有文章提到有些浏览器在收藏超长地址时也是会出现问题)时也是相当不友好的。当然,之前数据库字段设置时还是作为255bytes处理,现在可能要考虑扩充一下了。

时间: 2024-09-20 13:36:30

关于URL最大长度限制的相关资料查证_php技巧的相关文章

js window对象属性和方法相关资料整理_javascript技巧

window对象有以下方法: open close alert confirm prompt setTimeout clearTimeout setInterval clearInterval moveBy moveTo resizeBy resizeTo scrollBy scrollTo find back forward home stop print blur focus captureEvent enableExternalCapture disableExternalCapture

asp.net 获取IP的相关资料_实用技巧

ASP.net 获得客户端的IP,最常见的是使用下述代码: 复制代码 代码如下: string user_IP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; 对于了解代理服务器情况的人,我们会知道,如果用户使用了代理服务器,上述代码获得的是代理服务器的IP地址:如果用户使用了多个代理服务器,则是到达服务器的最后一个代理服务器的IP地址. REMOTE_ADDR 说明: 访问客户端的 IP

朋友网关于QQ相关的PHP代码(研究QQ的绝佳资料)_php技巧

复制代码 代码如下: <? /*************************************** ****************************************/ error_reporting(E_ALL ^ E_NOTICE); require_once( 'http.inc.php' ); require_once( 'class.Chinese.php'); //成功2xx     define( 'QQ_RETURN_SUCCESS',    200 );

php根据指定位置和长度获得子字符串的方法_php技巧

本文实例讲述了php根据指定位置和长度获得子字符串的方法.分享给大家供大家参考.具体分析如下: php的substr函数功能非常强大,不断可以从前往后去子字符串还可以从后往前取字符串 <?php $string = "beginning"; print("Position counted from left: ".substr($string,0,5)."\n"); print("Position counted form rig

PHP 常用时间函数资料整理_php技巧

php常用的时间函数 测试环境:php5.3.29 unix时间戳(从Unix 纪元(January 1 1970 00:00:00 GMT)到给定时间的秒数.).以下简称时间戳. 返回某一时间的时间戳. time(); 获取当前本机时间的时间戳. mktime(时,分,秒,月,日,年); //从右向左可以省略,省略到的参数用本机时间替换,比如省略了最后日和年就应用当前时间 22日 2016年. //年可写两位或四位数字.两位时0-69 对应于 2000-2069,70-100 对应于 1970

PHP URL地址获取函数代码(端口等) 推荐_php技巧

php 获得当前的脚本网址(只有路径) 复制代码 代码如下: function GetCurUrl() { if(!empty($_SERVER["REQUEST_URI"])) { $scrtName = $_SERVER["REQUEST_URI"]; $nowurl = $scrtName; } else { $scrtName = $_SERVER["PHP_SELF"]; if(empty($_SERVER["QUERY_ST

discuz目录文件资料汇总_php技巧

在某处收集来的discuz目录资料,二次开发挺有用的.记录下.(基于7.0的标准程序,部分与插件无关的文件不作说明) 文件颜色说明: 红色:程序核心文件,修改这类文件时千万要注意安全!橙色:做插件几乎不会用到的文件,大概了解功能就可以了,其实我也不推荐修改这些文件绿色:函数类文件,许多功能强大的自定义函数可以调用这类文件来使用蓝色:最标准的插件制作常用文件紫色:该文件被Zend加密,请不要修改这类文件每个目录里面都有一个空的index.htm,这是为了防止列目录用的,不必理会.根目录./(这里都

php时间计算相关问题小结_php技巧

本文实例总结了php时间计算相关问题.分享给大家供大家参考,具体如下: 1. php获取三个月前的日期 <?php header("content-Type: text/html; charset=utf-8");?> <?php $s_sdate=date("Y-m-d"); //当前时间 $moth_day=90; //月份 (转为天数) $s_edate=date("Y-m-d",(strtotime($s_sdate)-

收集的PHP中与数组相关的函数_php技巧

从ASP初入门到PHP,感觉到PHP的强大之一就是内置函数的丰富,比如先前学习的PHP日期时间函数,读写文件的相关函数等都无不表明了PHP的更专业.更令用户的使用得心应手. 一开始我对PHP函数的丰富功能很兴奋,随着对越来越多近乎变态多的函数接触之后,突然联想到了ASP内置函数的稀少,要完成某项特殊功能,常须自定义函数,随着应用的在增多,自己居然也有了一套常用的函数库.然而现在在PHP中,这些功能早已被标准化.规范化而浓缩为内置函数直接使用,曾经的ASP开发人员成为了PHP的普通用户. 但转念一