首页 > Web开发 > 详细

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

时间:2015-11-24 21:09:35      阅读:231      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!