关于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 相关文章推荐
php&amp;java(一)
Oct 09 PHP
PHP中file_exists与is_file,is_dir的区别介绍
Sep 12 PHP
如何利用PHP执行.SQL文件
Jul 05 PHP
php使用exec shell命令注入的方法讲解
Nov 12 PHP
json的键名为数字时的调用方式(示例代码)
Nov 15 PHP
PHP 抽象方法与抽象类abstract关键字介绍及应用
Oct 16 PHP
php使用Imagick生成图片的方法
Jul 31 PHP
PHP下载远程图片并保存到本地方法总结
Jan 22 PHP
php实现有序数组打印或排序的方法【附Python、C及Go语言实现代码】
Nov 10 PHP
简述php环境搭建与配置
Dec 05 PHP
Laravel框架生命周期与原理分析
Jun 12 PHP
PHP中非常有用却鲜有人知的函数集锦
Aug 17 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
snoopy 强大的PHP采集类使用实例代码
2010/12/09 PHP
apache+codeigniter 通过.htcaccess做动态二级域名解析
2012/07/01 PHP
说说PHP的autoLoad自动加载机制
2012/09/27 PHP
CURL的学习和应用(附多线程实现)
2013/06/03 PHP
THINKPHP项目开发中的日志记录实例分析
2014/12/01 PHP
在Node.js应用中使用Redis的方法简介
2015/06/24 Javascript
js实现当复选框选择匿名登录时隐藏登录框效果
2015/08/14 Javascript
js判断日期时间有效性的方法
2015/10/24 Javascript
ionic实现可滑动的tab选项卡切换效果
2020/04/15 Javascript
Angularjs实现mvvm式的选项卡示例代码
2016/09/08 Javascript
深入理解Node.js的HTTP模块
2016/10/12 Javascript
关于在LayUI中使用AJAX提交巨坑记录
2019/10/25 Javascript
JavaScript缓动动画函数的封装方法
2020/11/25 Javascript
[04:29]2016国际邀请赛中国区预选赛Ehome战队教练采访
2016/06/27 DOTA
[59:53]DOTA2-DPC中国联赛 正赛 VG vs Elephant BO3 第二场 3月6日
2021/03/11 DOTA
python连接mysql调用存储过程示例
2014/03/05 Python
Python使用django获取用户IP地址的方法
2015/05/11 Python
简单介绍Python的Django框架加载模版的方式
2015/07/20 Python
Python 给定的经纬度标注在地图上的实现方法
2019/07/05 Python
python PyQt5/Pyside2 按钮右击菜单实例代码
2019/08/17 Python
Django配置MySQL数据库的完整步骤
2019/09/07 Python
BrandAlley英国:法国折扣奢侈品网上零售商
2017/07/03 全球购物
租租车:国际租车、美国租车、欧洲租车、特价预订国外租车(中文服务)
2018/03/28 全球购物
汉森冲浪板:Hansen Surfboards
2018/05/19 全球购物
Pandora德国官网:购买潘多拉手链、戒指、项链和耳环
2020/02/20 全球购物
运动会100米解说词
2014/01/23 职场文书
优秀幼教自荐信
2014/02/03 职场文书
网吧消防安全责任书
2014/07/29 职场文书
项目合作协议书
2014/09/23 职场文书
计算机专业自荐信
2015/03/05 职场文书
python爬虫selenium模块详解
2021/03/30 Python
Nginx+Tomcat实现负载均衡、动静分离的原理解析
2021/03/31 Servers
PySwarms(Python粒子群优化工具包)的使用:GlobalBestPSO例子解析
2021/04/05 Python
浅谈pytorch中stack和cat的及to_tensor的坑
2021/05/20 Python
JS数组方法some、every和find的使用详情
2021/10/05 Javascript
golang语言指针操作
2022/04/14 Golang