代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //URL百分号编码 //URL编码会编码&,问号和其他标点符号。 NSString *urlString=@"http://myhost.com?query=This is a question"; NSString *encoded=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"--urlString--%@",urlString); NSLog(@"--endcoded--%@",encoded); }
输出:
2015-08-18 21:41:58.501 百分号编码[730:74165] --urlString--http://myhost.com?query=This is a question2015-08-18 21:41:58.501 百分号编码[730:74165] --endcoded--http://myhost.com?query=This%20is%20a%20question
参考资料:《iOS网络高级编程-iphone和iPad的企业应用开发》
新闻热点
疑难解答