URL 编码 - 从 %00 到 %8f

ASCII Value URL-encode ASCII Value URL-encode ASCII Value URL-encode
? %00 0 %30 ` %60
  %01 1 %31 a %61
  %02 2 %32 b %62
  %03 3 %33 c %63
  %04 4 %34 d %64
  %05 5 %35 e %65
  %06 6 %36 f %66
  %07 7 %37 g %67
backspace %08 8 %38 h %68
tab %09 9 %39 i %69
linefeed %0a : %3a j %6a
  %0b ; %3b k %6b
  %0c < %3c l %6c
c return %0d = %3d m %6d
  %0e > %3e n %6e
  %0f ? %3f o %6f
  %10 @ %40 p %70
  %11 A %41 q %71
  %12 B %42 r %72
  %13 C %43 s %73
  %14 D %44 t %74
  %15 E %45 u %75
  %16 F %46 v %76
  %17 G %47 w %77
  %18 H %48 x %78
  %19 I %49 y %79
  %1a J %4a z %7a
  %1b K %4b { %7b
  %1c L %4c | %7c
  %1d M %4d } %7d
  %1e N %4e ~ %7e
  %1f O %4f   %7f
space %20 P %50 ? %80
! %21 Q %51   %81
" %22 R %52 ? %82
# %23 S %53 ? %83
$ %24 T %54 ? %84
% %25 U %55 %85
& %26 V %56 ? %86
' %27 W %57 ? %87
( %28 X %58 ? %88
) %29 Y %59 %89
* %2a Z %5a ? %8a
+ %2b [ %5b ? %8b
, %2c \ %5c ? %8c
- %2d ] %5d   %8d
. %2e ^ %5e ? %8e
/ %2f _ %5f   %8f

URL 编码 - 从 %90 到 %ff

ASCII Value URL-encode ASCII Value URL-encode ASCII Value URL-encode
  %90 ? %c0 ? %f0
%91 ? %c1 ? %f1
%92 ? %c2 ò %f2
%93 ? %c3 ó %f3
%94 ? %c4 ? %f4
? %95 ? %c5 ? %f5
%96 ? %c6 ? %f6
%97 ? %c7 ÷ %f7
? %98 ? %c8 ? %f8
? %99 ? %c9 ù %f9
? %9a ? %ca ú %fa
? %9b ? %cb ? %fb
? %9c ? %cc ü %fc
  %9d ? %cd ? %fd
? %9e ? %ce ? %fe
? %9f ? %cf ? %ff
  %a0 ? %d0    
? %a1 ? %d1    
? %a2 ? %d2    
? %a3 ? %d3    
  %a4 ? %d4    
? %a5 ? %d5    
| %a6 ? %d6    
§ %a7   %d7    
¨ %a8 ? %d8    
? %a9 ? %d9    
? %aa ? %da    
? %ab ? %db    
? %ac ? %dc    
? %ad ? %dd    
? %ae ? %de    
? %af ? %df    
° %b0 à %e0    
± %b1 á %e1    
? %b2 ? %e2    
? %b3 ? %e3    
? %b4 ? %e4    
? %b5 ? %e5    
? %b6 ? %e6    
· %b7 ? %e7    
? %b8 è %e8    
? %b9 é %e9    
? %ba ê %ea    
? %bb ? %eb    
? %bc ì %ec    
? %bd í %ed    
? %be ? %ee    
? %bf ? %ef    

from : http://www.w3school.com.cn/tags/html_ref_urlencode.html

关于Url Encode 和 Url Decode

对于url中的中文字符,大多数网站都会做编码的处理,这里我们来探讨常用的2中编码和解码在perl中实现。

常用的编码方式有2种,GBK和UTF-8,因此URL编码也使用GBK的URL编码和UTF-8的URL编码。

1:GBK进行URL Encode。

1)先对字符串进行GBK编码。请注意,汉字本身采用的就是GBK编码,因此对于汉字,不应该再使用GBK编码。所以实际上如果是针对URL有汉字的URL进行URL编码,就直接使用URL编码函数即可。

2)然后进行URL编码

while(<>){
        chomp;
        my $gbkec = Encode::encode("gbk",$_); #对字符串进行GBK编码,如果是汉字要省略掉这一步,否则为重复编码。
        my $gbkuec = URI::Escape::uri_escape($gbkec); #对已经进行GBK编码的字符串进行URL编码
        my $encode = URI::Escape::uri_escape($_); #如果是汉字,可以直接进行URL编码
        print "$_ ->[GBK]$gbkec ->[URLencode]$gbkuec\n";
        print "$_ -> [URLencode]$encode\n";
}
测试输出:
@# ->[GBK]@# ->[URLencode]%40%23
@# -> [URLencode]%40%23

然后进行URL的GBK解码
解码的过程也要注意,汉字是不是重复使用了GBK解密,代码如下

while(<>){
        chomp;
        my $gbkec = URI::Escape::uri_unescape($_); #对URL进行解码
        my $chstr = Encode::decode("gbk",$gbkec); #对已经解码的url进行GBK解码,汉字本身为GBK编码,不用在进行GBK解码。

my $decode = URI::Escape::uri_unescape($_); #汉字编码的url可直接进行这一步
        print "$_ ->[URLdecode]$gbkec ->[GBKDecode]$chstr\n";
        print "$_ -> [URLdecode]$decode\n";
}

测试输出:
%40%23
%40%23 ->[URLdecode]@# ->[GBKDecode]@#
%40%23 -> [URLdecode]@#

2:UTF-8进行URL编码。

因为汉字采用的是GBK编码,因此不论在URL编码前还是在URL解码后,都需要调用相应函数进行操作。
对于UTF-8的编码和解码,我们使用UTF-8模块中的函数。
如下是编码后又解码的过程:

while(<>){
        chomp;

my $utf8str = $_;
        utf8::encode($utf8str); #进行UTF-8编码,函数直接操作变量
        my $encode = URI::Escape::uri_escape($utf8str); #对已经经过UTF-8编码的对象进行URL编码
        print "UTF-8 Encode:[$_] -> [$utf8str] -> [$encode]\n";

my $urldecode = URI::Escape::uri_unescape($encode); #对经过UTF-8编码的URL进行URL解码
        my $decode = $urldecode;
        utf8::decode($decode); #对经过URL解码后的字符串进行UTF-8解码
        print "UTF-8 Decode:[$encode] -> [$urldecode] -> [$decode]\n";
}

测试输出:
测试
UTF-8 Encode:[测试] -> [???????”] -> [%C2%B2%C3%A2%C3%8A%C3%94]
UTF-8 Decode:[%C2%B2%C3%A2%C3%8A%C3%94] -> [???????”] -> [测试]

总结:大多数国内网站对中文编码都采用GBK,因为这样会少一步编码处理。比如百度,即采用GBK编码。

但是国外网站大多采用UTF-8编码,因为UTF-8相对GBK更广泛。

from :  http://hi.baidu.com/youzhch/item/744df75338a741948c12ed96

  • html encode包含了252个字符,格式为‘&name;’,其中name为大小写敏感的;
  • xml encode只包含了5个字符,它们是$,<,>,',", 其格式与html相同;
  • url encode主要是ASCII的控制符号,Non-ASCII,url里的特殊字符(如/,?,&等),不安全字符(会引起二义性的),而encode规则是,使用%和16进制的2位数字(对应的ISO-Lation位置)组成。如空格就是%20,其位置为32.
  • HTML character references

    Character entity references have the format &name; where "name" is acase-sensitive alphanumericstring.

    The character entity references &lt;, &gt;, &quot; and &amp; are predefined in HTML and SGML, because <, >, " and & are already used to delimit markup.

    XML character references

    Unlike traditional HTML with its large range of character entity references, in XML there are only five predefined character entity references. These are used to escape characters that are markup sensitive in certain contexts:[7]

    • &amp; → & (ampersand, U+0026)
    • &lt; → < (less-than sign, U+003C)
    • &gt; → > (greater-than sign, U+003E)
    • &quot; → " (quotation mark, U+0022)
    • &apos; → ' (apostrophe, U+0027)

    &amp; has the special problem that it starts with the character to be escaped. A simple Internet search finds thousands of sequences &amp;amp;amp;amp; … in HTML pages for which the algorithm to replace an ampersand by the corresponding character entity reference was applied too often.

    http://en.wikipedia.org/wiki/Character_encodings_in_HTML

    List of XML and HTML character entity references

    • The XML specification defines five "predefined entities" representing special characters, and requires that all XML processors honor them.
    • The HTML 4 DTDs define 252 named entities, references to which act as mnemonic aliases for certain Unicode characters.

    http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

    URL encode

    ASCII Control characters
    Why: These characters are not printable.

    Non-ASCII characters
    Why: These are by definition not legal in URLs since they are not in the ASCII set.

    "Reserved characters"
    Why: URLs use some characters for special use in defining their syntax. When these characters are not used in their special role inside a URL, they need to be encoded.

    "Unsafe characters"
    Why: Some characters present the possibility of being misunderstood within URLs for various reasons. These characters should also always be encoded.

    How are characters URL encoded?
    URL encoding of a character consists of a "%" symbol, followed by the two-digit hexadecimal representation (case-insensitive) of the ISO-Latin code point for the character.

    Example

    • Space = decimal code point 32 in the ISO-Latin set.
    • 32 decimal = 20 in hexadecimal
    • The URL encoded representation will be "%20"

    XSS (Cross Site Scripting) Prevention Cheat Sheet
    http://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet

HTML Url 编码(Encode 和 Url Decode)相关推荐

  1. Base64的编码(Encode)与解码(Decode)

    Base64的编码(Encode)与解码(Decode) 推荐第一种 效率更高. 第一种:java8 新版本 @Testpublic void test1(){//现在Base64编码 import ...

  2. c语言实现url编码源码,URL encode 与 URL decode 的C语言实现

    本文代码为从PHP代码中修改而来,只保留了2个函数. int php_url_decode(char *str, int len); char *php_url_encode(char const * ...

  3. php解析url编码,php对URL传参进行编码和解码解析

    1. 对URL 传递的参数进行编码 使用URL 传递参数数据,就是在 URL地址后面加上适当的参数.URL 实体对这些参数进行处理.其使用的方式如下面的格式: 显而易见,这种方法将会把参数暴露出来,安 ...

  4. php中url编码地址栏,php url地址栏传中文乱码解决方法集合_PHP

    php地址栏传中文$_GET下来后乱码,urlencode和urldecode用法详解 url编码 语法: string urlencode(string str); 返回值: 字符串 函数种类: 编 ...

  5. php html url编码,html中url编码是什么?有什么用?

    本篇文章给大家带来的内容是介绍HTML中的URL编码是什么,有什么用.有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助. 我们在介绍URL编码之前,首先来了解一下URL是什么,URL的相 ...

  6. Java如何进行Base64的编码(Encode)与解码(Decode)?

    关于base64编码Encode和Decode编码的几种方式 Base64是一种能将任意Binary资料用64种字元组合成字串的方法,而这个Binary资料和字串资料彼此之间是可以互相转换的,十分方便 ...

  7. Python编码encode()与解码decode()介绍与示例演示

    1.编码与解码介绍 位:计算机最小的单位 二进制中的一位 用二进制的 0/1表示. 字节:八位组成一个字节. 字符:我们肉眼可见的文字与符号. 字符集:字符的集合. 编码:将字符转换成计算机可识别的0 ...

  8. 火狐浏览器设置url编码_关于URL编码

    一.问题的由来 URL就是网址,只要上网,就一定会用到. 一般来说,URL只能使用英文字母.阿拉伯数字和某些标点符号,不能使用其他文字和符号.比如,世界上有英文字母的网址"http://ww ...

  9. URL原理、URL编码、URL特殊字符

    From: http://blog.csdn.net/chenlycly/article/details/51820727 From: http://blog.csdn.net/zmx729618/a ...

  10. 070_html url编码

    1. URL编码 1.1. URL只能使用ASCII字符集来通过因特网进行发送. 1.2. 由于URL常常会包含ASCII集合之外的字符, URL必须转换为有效的ASCII格式. 1.3. URL编码 ...

最新文章

  1. SqlServer的SSIS导入导出数据时找不到连接错误处理
  2. Caffe 深度学习框架介绍
  3. C语言实现了一个顺序表(附完整源码)
  4. Mysql5换成Mysql8之后报错java.lang.ClassNotFoundException: com.mysql.jdbc.driver的问题解决
  5. java软件工程师自我评价_电子技术研发工程师简历自我评价填写样本
  6. 什么版本的linux可以用ps,在linux上使用ps(转载)
  7. ctf题目:看不见的flag_记一次江西省信息安全线下CTF比赛
  8. Google在东京召开了一场AI座谈会
  9. Maven项目的pom.xml配置文件格式初识
  10. .Net语言 APP开发平台——Smobiler学习日志:用Gridview控件设计较复杂的表单
  11. C# List 深复制
  12. Servlet九大内置对象
  13. 点云应用——三维空间边界点排序+机器人轨迹引导(1)
  14. 数论著作读书笔记(2013-04-14 23:22)
  15. 小狼毫[rime_win][眀月拼音]简单配置方法
  16. “手把手教你设计”—12个最佳手机APP界面设计教程
  17. Mathmatica9 注册不了
  18. 15、ESP-MESH组网
  19. #同余最短路# [51nod] 遥远的旅途
  20. 麻省理工科技评论:AI预言的七宗罪(上)

热门文章

  1. 最透彻的分析!NTC热敏电阻与浪涌电流,热启动不会失效?
  2. 我在2022北大夏令营被吊起来打
  3. python - 单因子分析
  4. CComObject 。。。(转)
  5. 【实验技术笔记】利用重组载体做基因过表达(pCDH载体)
  6. 360搜索是废了还是彻底商业化了?
  7. 咸鱼软件应用—Arnold2019安装
  8. vue解决火狐浏览器滚动条问题
  9. windows 文件夹属性全部都为只读。怎么解决?
  10. 通达信指标没有了怎么找回