关于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 相关文章推荐
一个程序下载的管理程序(四)
Oct 09 PHP
在线增减.htpasswd内的用户
Oct 09 PHP
[原创]PHP中通过ADODB库实现调用Access数据库之修正版本
Dec 31 PHP
php 论坛采集程序 模拟登陆,抓取页面 实现代码
Jul 09 PHP
PHP函数常用用法小结
Feb 08 PHP
浅析php中三个等号(===)和两个等号(==)的区别
Aug 06 PHP
浅谈使用 PHP 进行手机 APP 开发(API 接口开发)
Aug 11 PHP
PHP中使用GD库创建圆形饼图的例子
Nov 19 PHP
PHP利用APC模块实现文件上传进度条的方法
Jan 26 PHP
php查找字符串中第一个非0的位置截取
Feb 27 PHP
php 解析非标准json、非规范json
Apr 01 PHP
PHP实现rar解压读取扩展包小结
Jun 03 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 数据结构 算法描述 冒泡排序 bubble sort
2011/07/10 PHP
基于PHP实现假装商品限时抢购繁忙的效果
2015/10/16 PHP
PHP序列化操作方法分析
2016/09/28 PHP
js页面滚动时层智能浮动定位实现(jQuery/MooTools)
2011/08/23 Javascript
javascript真的不难-回顾一下基础知识
2013/01/15 Javascript
JavaScript:Div层拖动效果实例代码
2013/08/06 Javascript
js清除input中type等于file的值域(示例代码)
2013/12/24 Javascript
javascript模拟php函数in_array
2015/04/27 Javascript
再JavaScript的jQuery库中编写动画效果的指南
2015/08/13 Javascript
ClearTimeout消除闪动实例代码
2016/02/29 Javascript
Node.js环境下JavaScript实现单链表与双链表结构
2016/06/12 Javascript
JS使用cookie设置样式的方法
2016/06/30 Javascript
详谈jQuery unbind 删除绑定事件 / 移除标签方法
2017/03/02 Javascript
JavaScript输入框字数实时统计更新
2017/06/17 Javascript
bootstrap多层模态框滚动条消失的问题
2017/07/21 Javascript
简单快速的实现js计算器功能
2017/08/17 Javascript
element ui 对话框el-dialog关闭事件详解
2018/02/26 Javascript
Vue 中使用vue2-highcharts实现top功能的示例
2018/03/05 Javascript
JS同步、异步、延迟加载的方法
2018/05/05 Javascript
Python 列表排序方法reverse、sort、sorted详解
2016/01/22 Python
python 用正则表达式筛选文本信息的实例
2018/06/05 Python
python看某个模块的版本方法
2018/10/16 Python
Python函数定义及传参方式详解(4种)
2019/03/18 Python
Django之提交表单与前后端交互的方法
2019/07/19 Python
Python threading的使用方法解析
2019/08/28 Python
详解Python中字符串前“b”,“r”,“u”,“f”的作用
2019/12/18 Python
Canvas多边形绘制的实现方法
2019/08/05 HTML / CSS
中专毕业生自我鉴定
2014/02/02 职场文书
行政办公室岗位职责
2014/03/18 职场文书
公民授权委托书范本
2014/09/17 职场文书
抄袭同学作业检讨书1000字
2014/11/20 职场文书
小班上学期个人总结
2015/02/12 职场文书
2015年世界急救日宣传活动方案
2015/05/06 职场文书
干部考核工作总结2015
2015/07/24 职场文书
复制别人的成功真的会成功吗?
2019/10/17 职场文书
nginx处理http请求实现过程解析
2021/03/31 Servers