关于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
单点登录 Ucenter示例分析
Oct 29 PHP
解决CodeIgniter伪静态失效
Jun 09 PHP
ThinkPHP实现带验证码的文件上传功能实例
Nov 01 PHP
PHP实现抓取HTTPS内容
Dec 01 PHP
smarty内置函数section的用法
Jan 22 PHP
php中10个不同等级压缩优化图片操作示例
Nov 14 PHP
Zend Framework数据库操作技巧总结
Feb 18 PHP
PHP操作MySQL中BLOB字段的方法示例【存储文本与图片】
Sep 15 PHP
Laravel框架实现利用监听器进行sql语句记录功能
Jun 06 PHP
php实现生成PDF文件的方法示例【基于FPDF类库】
Jul 21 PHP
PHP7 echo和print语句实例用法
Feb 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
PHP中GET变量的使用
2006/10/09 PHP
tp5.1 框架路由操作-URL生成实例分析
2020/05/26 PHP
JQuery里选择超链接的实现代码
2011/05/22 Javascript
jQuery EasyUI API 中文文档 - Menu菜单
2011/10/03 Javascript
JavaScript入门之基本函数详解
2011/10/21 Javascript
web网页按比例显示图片实现原理及js代码
2013/08/09 Javascript
现代 JavaScript 开发编程风格Idiomatic.js指南中文版
2014/05/28 Javascript
jQuery fadeOut 异步实例代码详解
2016/08/18 Javascript
jQuery插件实现可输入和自动匹配的下拉框
2016/10/24 Javascript
js 模仿锚点定位的实现方法
2016/11/19 Javascript
JQuery统计input和textarea文字输入数量(代码分享)
2016/12/29 Javascript
Vue.js在数组中插入重复数据的实现代码
2017/11/17 Javascript
Vue使用vux-ui自定义表单验证遇到的问题及解决方法
2018/05/10 Javascript
vue自定义一个v-model的实现代码
2018/06/21 Javascript
layui 给数据表格加序号的方法
2018/08/20 Javascript
原生JavaScript实现幻灯片效果
2021/02/19 Javascript
[13:21]DOTA2国际邀请赛采访专栏:RSnake战队国士无双,Fnatic.Fly
2013/08/06 DOTA
寻找网站后台地址的python脚本
2014/09/01 Python
Python代码解决RenderView窗口not found问题
2016/08/28 Python
通过实例学习Python Excel操作
2020/01/06 Python
keras模型保存为tensorflow的二进制模型方式
2020/05/25 Python
Python如何在循环内使用list.remove()
2020/06/01 Python
python实现批量转换图片为黑白
2020/06/16 Python
Brookstone美国官网:独特新奇产品
2017/03/04 全球购物
教师网络培训感言
2014/03/09 职场文书
公司开业庆典主持词
2014/03/21 职场文书
产品质量承诺书范文
2014/03/27 职场文书
教师三严三实对照检查材料
2014/09/25 职场文书
2014年作风建设剖析材料
2014/10/23 职场文书
2014小学语文教师个人工作总结
2014/12/03 职场文书
小学英语教学经验交流材料
2015/11/02 职场文书
企业管理不到位检讨书
2019/06/27 职场文书
SQL Server作业失败:无法确定所有者是否有服务器访问权限的解决方法
2021/06/30 SQL Server
nginx内存池源码解析
2021/11/20 Servers
2022新作动画《福星小子》释出宣传影片 加入内田真礼&宫野真守配音演出
2022/04/08 日漫
python实现双向链表原理
2022/05/25 Python