关于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 相关文章推荐
Linux下将excel数据导入到mssql数据库中的方法
Feb 08 PHP
使用VisualStudio开发php的图文设置方法
Aug 21 PHP
基于Snoopy的PHP近似完美获取网站编码的代码
Oct 23 PHP
超级实用的7个PHP代码片段分享
Jan 05 PHP
php中配置文件操作 如config.php文件的读取修改等操作
Jul 07 PHP
PHP正则替换函数preg_replace和preg_replace_callback使用总结
Sep 22 PHP
PHP实现设计模式中的抽象工厂模式详解
Oct 11 PHP
PHP中使用Imagick实现各种图片效果实例
Jan 21 PHP
php实现图片上传并利用ImageMagick生成缩略图
Mar 14 PHP
PHP模块化安装教程
Jun 01 PHP
PHP+Redis链表解决高并发下商品超卖问题(实现原理及步骤)
Aug 03 PHP
PHP引擎php.ini参数优化深入讲解
Mar 24 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
如何开发一个虚拟域名系统
2006/10/09 PHP
PHP下用rmdir实现删除目录的三种方法小结
2008/04/20 PHP
PHP实现接收二进制流转换成图片的方法
2017/01/10 PHP
window.js 主要包含了页面的一些操作
2009/12/23 Javascript
javascript避免数字计算精度误差的方法详解
2014/03/05 Javascript
js简单的表格添加行和删除行操作示例
2014/03/31 Javascript
详解JavaScript编程中的数组结构
2015/10/24 Javascript
JavaScript中输出信息的方法(信息确认框-提示输入框-文档流输出)
2016/06/12 Javascript
浅析Javascript ES6中的原生Promise
2016/08/25 Javascript
CSS3 media queries结合jQuery实现响应式导航
2016/09/30 Javascript
原生js实现新闻列表展开/收起全文功能
2017/01/20 Javascript
js实现文本上下来回滚动
2017/02/03 Javascript
js实现短信发送倒计时功能(正则验证)
2017/02/10 Javascript
手机注册发送验证码倒计时的简单实例
2017/11/15 Javascript
JavaScript同源策略和跨域访问实例详解
2018/04/03 Javascript
Intellij IDEA搭建vue-cli项目的方法步骤
2018/10/20 Javascript
一篇文章带你搞懂Vue虚拟Dom与diff算法
2020/08/25 Javascript
VUE UPLOAD 通过ACTION返回上传结果操作
2020/09/07 Javascript
[02:57]DOTA2亚洲邀请赛 SECRET战队出场宣传片
2015/02/07 DOTA
对Python3中的print函数以及与python2的对比分析
2018/05/02 Python
详解python中各种文件打开模式
2020/01/19 Python
python数据预处理 :样本分布不均的解决(过采样和欠采样)
2020/02/29 Python
python基于pexpect库自动获取日志信息
2021/02/01 Python
Html5应用程序缓存(Cache manifest)
2018/06/04 HTML / CSS
墨西哥皇宫度假村预订:Palace Resorts
2018/06/16 全球购物
软件生产职位结构化面试主要考察要素及面试题库
2015/06/12 面试题
工程力学硕士生的自我评价范文
2013/11/16 职场文书
在校学生职业规划范文
2014/01/08 职场文书
企业安全生产月活动总结
2014/07/05 职场文书
小学教师自我剖析材料
2014/09/29 职场文书
2016年寒假生活小结
2015/10/10 职场文书
2016年寒假见闻
2015/10/10 职场文书
幼儿园中班教学反思
2016/03/03 职场文书
如何在Python项目中引入日志
2021/05/31 Python
SpringBoot 拦截器妙用你真的了解吗
2021/07/01 Java/Android
Android基础入门之dataBinding的简单使用教程
2022/06/21 Java/Android