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


Posted in PHP onDecember 23, 2014

在开发调试支付宝接口时,突然发现支付宝接口的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处理,现在可能要考虑扩充一下了。

PHP 相关文章推荐
PHPlet在Windows下的安装
Oct 09 PHP
PHP中实现汉字转区位码应用源码实例解析
Jun 14 PHP
PHPUnit PHP测试框架安装方法
Mar 23 PHP
php顺序查找和二分查找示例
Mar 27 PHP
PHP中的socket_read和socket_recv区别详解
Feb 09 PHP
PHP实现简单搜歌的方法
Jul 28 PHP
PHP+MySQL实现无极限分类栏目的方法
Dec 23 PHP
PHP引用返回用法示例
May 28 PHP
PHP编写文件多服务器同步程序
Jul 02 PHP
PHP实现的简单在线计算器功能示例
Aug 02 PHP
php中青蛙跳台阶的问题解决方法
Oct 14 PHP
php 多个变量指向同一个引用($b = &amp;$a)用法分析
Nov 13 PHP
php实现基于微信公众平台开发SDK(demo)扩展的方法
Dec 22 #PHP
php微信公众开发之获取周边酒店信息的方法
Dec 22 #PHP
php天翼开放平台短信发送接口实现方法
Dec 22 #PHP
php进行支付宝开发中return_url和notify_url的区别分析
Dec 22 #PHP
WebQQ最新登陆协议的用法
Dec 22 #PHP
腾讯微博提示missing parameter errorcode 102 错误的解决方法
Dec 22 #PHP
php有道翻译api调用方法实例
Dec 22 #PHP
You might like
php empty,isset,is_null判断比较(差异与异同)
2010/10/19 PHP
php解析url并得到url中的参数及获取url参数的四种方式
2015/10/26 PHP
Yii2.0使用阿里云OSS的SDK上传图片、下载、删除图片示例
2017/09/20 PHP
php微信开发之图片回复功能
2018/06/14 PHP
javascript 兼容鼠标滚轮事件
2009/04/07 Javascript
30个让人兴奋的视差滚动(Parallax Scrolling)效果网站
2012/03/04 Javascript
JS 实现Table相同行的单元格自动合并示例代码
2013/08/27 Javascript
javaScript array(数组)使用字符串作为数组下标的方法
2013/11/19 Javascript
JS实现自动固定顶部的悬浮菜单栏效果
2015/09/16 Javascript
javascript运算符——逻辑运算符全面解析
2016/06/27 Javascript
微信小程序引用公共js里的方法的实例详解
2017/08/17 Javascript
vue 实现在函数中触发路由跳转的示例
2018/09/01 Javascript
Angular4.0动画操作实例详解
2019/05/10 Javascript
[05:24]TI9采访——教练
2019/08/24 DOTA
利用python微信库itchat实现微信自动回复功能
2017/05/18 Python
python实现二叉树的遍历
2017/12/11 Python
Python中 传递值 和 传递引用 的区别解析
2018/02/22 Python
Python zip()函数用法实例分析
2018/03/17 Python
Windows下pycharm创建Django 项目(虚拟环境)过程解析
2019/09/16 Python
Python numpy数组转置与轴变换
2019/11/15 Python
查看jupyter notebook每个单元格运行时间实例
2020/04/22 Python
Python爬虫requests库多种用法实例
2020/05/28 Python
css3圆角边框和边框阴影示例
2014/05/05 HTML / CSS
浅析与CSS3的loading动画加载相关的transition优化
2015/05/18 HTML / CSS
探索HTML5本地存储功能运用技巧
2016/03/02 HTML / CSS
美国市场上最实惠的送餐服务:Dinnerly
2018/03/18 全球购物
美国购买当代和现代家具网站:MODTEMPO
2018/07/20 全球购物
澳大利亚游乐场设备品牌:Lifespan Kids
2019/05/24 全球购物
描述一下JVM加载class文件的原理机制
2013/12/08 面试题
北京某科技有限公司C# .net笔试题
2014/09/27 面试题
城市规划毕业生求职信
2013/10/10 职场文书
终止劳动合同协议书
2014/10/05 职场文书
检讨书范文
2015/01/27 职场文书
2015年财务人员工作总结
2015/04/10 职场文书
【海涛dota解说】DCG联赛第一周 LGD VS DH
2022/04/01 DOTA
多线程Spring通过@Scheduled实现定时任务
2022/05/25 Java/Android