码迷,mamicode.com
首页 > Web开发 > 详细

url出现特殊字符,需要进行编码

时间:2015-11-24 21:11:53      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

1) 网络访问请求:中文空格字符编码/解码

stringByAddingPercentEscapesUsingEncoding(只对 `#%^{}[]|\"<> 加空格共14个字符编码,不包括”&?”等符号), ios9将淘汰,建议用stringByAddingPercentEncodingWithAllowedCharacters方法

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

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

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

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

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

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

(2)网络访问请求:中文空格字符解码

stringByRemovingPercentEncoding ---- xcode7可能会提示要将stringByAddingPercentEscapesUsingEncoding替换成此方法,要根据是否是解码来区分

*/
//代替stringByAddingPercentEscapesUsingEncoding

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

例如:

           NSString *urlStr = [NSString stringWithFormat:@"%@/uploadFeedback?sessionID=%@&content=%@", kMainURL, [MySharedClass      sharedInstance].sessionID, _textView.text];

  

          urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

url出现特殊字符,需要进行编码

标签:

原文地址:http://www.cnblogs.com/fengkuangIT/p/4992762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!