关于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 相关文章推荐
Discuz 模板引擎的封装类代码
Jul 18 PHP
thinkphp的c方法使用示例
Feb 24 PHP
php读取富文本的时p标签会出现红线是怎么回事
May 13 PHP
PHP开发注意事项总结
Feb 04 PHP
php上传文件并存储到mysql数据库的方法
Mar 16 PHP
PHP5.3以上版本安装ZendOptimizer扩展
Mar 27 PHP
详解PHP中的Traits
Jul 29 PHP
php基于session实现数据库交互的类实例
Aug 03 PHP
CI框架(ajax分页,全选,反选,不选,批量删除)完整代码详解
Nov 01 PHP
PHP读取文件的常见几种方法
Nov 03 PHP
thinkPHP引入类的方法详解
Dec 08 PHP
Yii框架小部件(Widgets)用法实例详解
May 15 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
Laravel中的Blade模板引擎示例详解
2017/10/10 PHP
Yii2.0框架实现带分页的多条件搜索功能示例
2019/02/20 PHP
COM中获取JavaScript数组大小的代码
2009/11/22 Javascript
js split 的用法和定义 js split分割字符串成数组的实例代码
2012/05/13 Javascript
javascript学习笔记(十五) js间歇调用和超时调用
2012/06/20 Javascript
JS网页播放声音实现代码兼容各种浏览器
2013/09/22 Javascript
JavaScript中使用Substring删除字符串最后一个字符
2013/11/03 Javascript
js setTimeout()函数介绍及应用以倒计时为例
2013/12/12 Javascript
利用javascript判断文件是否存在
2013/12/31 Javascript
javascript实现base64 md5 sha1 密码加密
2015/09/09 Javascript
javascript瀑布流式图片懒加载实例解析与优化
2016/02/23 Javascript
浅谈Angular.js中使用$watch监听模型变化
2017/01/10 Javascript
使用vue实现点击按钮滑出面板的实现代码
2017/01/10 Javascript
微信小程序 template模板详解及实例
2017/02/21 Javascript
前端主流框架vue学习笔记第二篇
2017/07/26 Javascript
jquery easyui如何实现格式化列
2017/07/30 jQuery
jQueryUI Sortable 应用Demo(分享)
2017/09/07 jQuery
利用jQuery+localStorage实现一个简易的计时器示例代码
2017/12/25 jQuery
关于JSON解析的实现过程解析
2019/10/08 Javascript
vue 实现click同时传入事件对象和自定义参数
2021/01/29 Vue.js
[03:24]DOTA2超级联赛专访hao 大翻盘就是逆袭
2013/05/24 DOTA
深入讲解Python中面向对象编程的相关知识
2015/05/25 Python
用python记录运行pid,并在需要时kill掉它们的实例
2017/01/16 Python
Python异常的检测和处理方法
2018/10/26 Python
使用urllib库的urlretrieve()方法下载网络文件到本地的方法
2018/12/19 Python
Python中整数的缓存机制讲解
2019/02/16 Python
Python 下载及安装详细步骤
2019/11/04 Python
美国知名奢侈美容品牌零售商:Cos Bar
2017/04/21 全球购物
美国家居装饰店:Z Gallerie
2020/12/28 全球购物
存储过程的优点有哪些
2012/09/27 面试题
应聘医药代表职位求职信
2013/10/21 职场文书
机关会计岗位职责
2014/04/08 职场文书
煤矿安全知识竞赛活动总结
2014/07/07 职场文书
小区的门卫岗位职责
2014/10/01 职场文书
授权委托书协议书
2014/10/16 职场文书
退休欢送会主持词
2015/07/01 职场文书