关于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+Tidy-完美的XHTML纠错+过滤
Apr 10 PHP
php若干单维数组遍历方法的比较
Sep 20 PHP
PHP逐行输出(ob_flush与flush的组合)
Feb 04 PHP
php获取随机数组列表的方法
Nov 13 PHP
php中fsockopen用法实例
Jan 05 PHP
PHP实现采集抓取淘宝网单个商品信息
Jan 08 PHP
基于PHP如何把汉字转化为拼音
Dec 11 PHP
Zend Framework入门教程之Zend_Db数据库操作详解
Dec 08 PHP
php 从一个数组中随机的取出若干个不同的数实例
Dec 31 PHP
PHP实现的回溯算法示例
Aug 15 PHP
php实现socket推送技术的示例
Dec 20 PHP
php 利用socket发送GET,POST请求的实例代码
Jul 04 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
什么是短波收听SWL
2021/03/01 无线电
php中用于检测一个地理IP地址是否可用的代码
2012/02/19 PHP
php array的学习笔记
2012/05/10 PHP
基于php实现随机合并数组并排序(原排序)
2015/11/26 PHP
在Win2003(64位)中配置IIS6+PHP5.2.17+MySQL5.5的运行环境
2016/04/04 PHP
PHP基于phpqrcode类生成二维码的方法详解
2018/03/14 PHP
PHP 结合 Boostrap 结合 js 实现学生列表删除编辑及搜索功能
2019/05/21 PHP
php中的buffer缓冲区用法分析
2019/05/31 PHP
原生js实现fadein 和 fadeout淡入淡出效果
2014/06/05 Javascript
分享一个常用的javascript静态类
2014/12/31 Javascript
js实现鼠标感应图片展示的方法
2015/02/27 Javascript
Jquery ajax加载等待执行结束再继续执行下面代码操作
2015/11/24 Javascript
JavaScript仿微信(电话)联系人列表滑动字母索引实例讲解(推荐)
2017/08/16 Javascript
nodejs更改项目端口号的方法
2018/05/13 NodeJs
详解vue-cli中模拟数据的两种方法
2018/07/03 Javascript
微信小程序异步API为Promise简化异步编程的操作方法
2018/08/14 Javascript
js数组去重的方法总结
2019/01/18 Javascript
JQuery事件委托原理与用法实例分析
2019/05/13 jQuery
vue 组件内获取actions的response方式
2019/11/08 Javascript
微信小程序纯文本实现@功能
2020/04/08 Javascript
vue自定义树状结构图的实现方法
2020/10/18 Javascript
[51:29]完美世界DOTA2联赛循环赛 Matador vs Forest BO2第一场 11.05
2020/11/05 DOTA
[45:59]完美世界DOTA2联赛PWL S2 FTD vs GXR 第二场 11.22
2020/11/24 DOTA
Python 安装setuptools和pip工具操作方法(必看)
2017/05/22 Python
解决selenium+Headless Chrome实现不弹出浏览器自动化登录的问题
2021/01/09 Python
承办会议欢迎词
2014/01/17 职场文书
校园十大歌手策划书
2014/02/01 职场文书
绿色小区申报材料
2014/08/22 职场文书
2015年元旦演讲稿
2014/09/12 职场文书
员工加薪申请报告
2015/05/15 职场文书
2019年中学生的思想品德评语集锦
2019/12/19 职场文书
详解MySQL 用户权限管理
2021/04/20 MySQL
python源码剖析之PyObject详解
2021/05/18 Python
深入解析NumPy中的Broadcasting广播机制
2021/05/30 Python
小程序实现文字循环滚动动画
2021/06/14 Javascript
Python游戏开发实例之graphics实现AI五子棋
2021/11/01 Python