美文网首页
iOS OC URL转码

iOS OC URL转码

作者: 机械师shijier | 来源:发表于2019-12-24 10:35 被阅读0次

    1.NSString 方法

    stringByAddingPercentEncodingWithAllowedCharacters  需要传一个  NSCharacterSet  对象

    如[NSCharacterSet  URLQueryAllowedCharacterSet]

    URLFragmentAllowedCharacterSet "#%<>[\]^`{|}

    URLHostAllowedCharacterSet      "#%/<>?@\^`{|}

    URLPasswordAllowedCharacterSet  "#%/:<>?@[\]^`{|}

    URLPathAllowedCharacterSet      "#%;<>?[\]^`{|}

    URLQueryAllowedCharacterSet    "#%<>[\]^`{|}

    URLUserAllowedCharacterSet      "#%/:<>?@[\]^`

    2.  

    let customAllowedSet = NSCharacterSet(charactersInString:"`#%^{}\"[]|\\<> ").invertedSet

    NSString *urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];

    相关文章

      网友评论

          本文标题:iOS OC URL转码

          本文链接:https://www.haomeiwen.com/subject/knpxoctx.html