网络缓存分析

2018-08-21  本文已影响7人  简_爱SimpleLove

特殊字符的转译

    NSString *url = @"http://www.baidu.com/test=1=+&===中文==";
    NSString *urlOne = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    static NSString * const kAFCharactersGeneralDelimitersToEncode = @":#[]@"; // does not include "?" or "/" due to RFC 3986 - Section 3.4
    static NSString * const kAFCharactersSubDelimitersToEncode = @"!$&'()*+,;=";
    NSMutableCharacterSet * allowedCharacterSet = [[NSCharacterSet URLQueryAllowedCharacterSet] mutableCopy];
    [allowedCharacterSet removeCharactersInString:[kAFCharactersGeneralDelimitersToEncode stringByAppendingString:kAFCharactersSubDelimitersToEncode]];
    NSString *urlT = [url stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet];

针对于特殊字符,urlOne只能将中文进行转码,如果需要将其他特殊字符也进行转码,就必须要用urlT这样的方法

 根据RFC 3986的规定:URL百分比编码的保留字段分为:
 1.   :  #  [  ]  @  ?  /
 2.   !  $  &  '  (  )  *  +  ,  ; =
 ?和/在query表中允许不被转译,  :#[]@和!$&'()*+,;= 都要被转译,
 也就是在URLQueryAllowedCharacterSet中删除这些字符

下载的缓存数据一般在当程序进入后台的时候,才进行删除,一般的本地会存储一周

上一篇下一篇

猜你喜欢

热点阅读