
一、iOS 中的NSURL编码
iOS 中,NSURL 的基本样式是
scheme://username:password@host:port/path?query#fragment
RFC 1738规定:
Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.
On the other hand, characters that are not required to be encoded
(including alphanumerics) may be encoded within the scheme-specific
part of a URL, as long as they are not being used for a reserved
purpose.
所以对一些不符合规定的字符我们需要进行编码。就是“URL编码”,也叫“百分号编码”。一般都是把不符合的字符转成UTF-8编码,然后每两位(2 BYTE)前面加上‘%’。
在以前,我们经常使用下面的函数去排除 @"!*'();