关于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 相关文章推荐
Joomla下利用configuration.php存储简单数据
May 19 PHP
自己在做项目过程中学到的PHP知识收集
Aug 20 PHP
php5.3 注意事项说明
Jul 01 PHP
2个比较经典的PHP加密解密函数分享
Jul 01 PHP
php计算两个日期相差天数的方法
Mar 14 PHP
PHP微信支付实例解析
Jul 22 PHP
PHP flush 函数使用注意事项
Aug 26 PHP
PHP实现的迪科斯彻(Dijkstra)最短路径算法实例
Sep 16 PHP
PHP连接sftp并下载文件的方法教程
Aug 26 PHP
PHP基于面向对象封装的分页类示例
Mar 15 PHP
PHP使用redis位图bitMap 实现签到功能
Oct 08 PHP
php与阿里云短信接口接入操作案例分析
May 27 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 文件夹删除、php清除缓存程序
2009/08/25 PHP
PHP代码保护--Zend Guard的使用详解
2013/06/03 PHP
Laravel 5框架学习之子视图和表单复用
2015/04/09 PHP
Zend Framework入门应用实例详解
2016/12/11 PHP
PHP常用正则表达式精选(推荐)
2019/05/28 PHP
PHP设计模式概论【概念、分类、原则等】
2020/05/01 PHP
jquery.ui.draggable中文文档(原文翻译)
2013/11/15 Javascript
Jqgrid设置全选(选择)及获取选择行的值示例代码
2013/12/28 Javascript
jquery form表单序列化为对象的示例代码
2014/03/05 Javascript
初识SmartJS - AOP三剑客
2014/06/08 Javascript
jQuery validate插件submitHandler提交导致死循环解决方法
2016/01/21 Javascript
Bootstrap组件系列之福利篇几款好用的组件(推荐)
2016/06/23 Javascript
nodejs基础应用
2017/02/03 NodeJs
js实现以最简单的方式将数组元素添加到对象中的方法
2017/12/20 Javascript
微信小程序首页的分类功能和搜索功能的实现思路及代码详解
2018/09/11 Javascript
Angular事件之不同组件间传递数据的方法
2018/11/15 Javascript
vue微信分享到朋友圈 vue微信发送给好友
2018/11/28 Javascript
JavaScript编码小技巧分享
2020/09/17 Javascript
[48:52]DOTA2上海特级锦标赛A组小组赛#2 Secret VS CDEC第一局
2016/02/25 DOTA
Python基于scrapy采集数据时使用代理服务器的方法
2015/04/16 Python
django批量导入xml数据
2016/10/16 Python
python读取txt文件中特定位置字符的方法
2018/12/24 Python
简单了解Python3里的一些新特性
2019/07/13 Python
Python字符串中添加、插入特定字符的方法
2019/09/10 Python
python next()和iter()函数原理解析
2020/02/07 Python
Python中使用threading.Event协调线程的运行详解
2020/05/02 Python
django 利用Q对象与F对象进行查询的实现
2020/05/15 Python
Kathmandu美国网站:新西兰户外运动品牌
2019/03/23 全球购物
会计电算化专业应届大学生求职信
2013/10/22 职场文书
英文自荐信
2013/12/15 职场文书
对党的十八届四中全会的期盼
2014/10/17 职场文书
2014年政风行风自查自纠报告
2014/10/21 职场文书
文员岗位职责范本
2015/04/16 职场文书
终止解除劳动合同证明书
2015/06/17 职场文书
jackson json序列化实现首字母大写,第二个字母需小写
2021/06/29 Java/Android
《极主夫道》真人电影正式预告 定档6月3日上映
2022/04/05 日漫