六 中文转码
- 断定需不须要转码操作:看请求路径是否含有中文,含有的话,就须要转码
- 设置代劳的多一个参数的办法中:如不雅设置的为NO,那么手动开启的时刻,底层start会把线程参加到runloop中,然则如不雅设置的为yes,那么和没有参数的时刻一样,须要手动创建runloop.
1.1 performSelector: 办法
GET转码:
- #pragma mark - GET转码
- - (void)get
- {
- //肯定请求字符串
- NSString *strurl = @"http://120.25.226.186:32812/login2?username=(须要转的汉字)&pwd=520it&type=JSON";
- //转码
- strurl = [strurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- //肯定路径
- NSURL *url = [NSURL URLWithString:strurl];
- //创建可变的请求对象
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
- //发送请求--->GET请求
- [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
- //解析数据
- if (connectionError == nil) {
- NSLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
- }else{
- NSLog(@"%@",connectionError);
- }
- }];
- }
POST转码:
- #pragma mark - POST转码
- - (void)post
- {
- //肯定请求路径的字符串
- NSString *urlstr = @"http://120.25.226.186:32812/login2"
推荐阅读
沙龙晃荡 | 3月31日 京东、微博、华为拭魅战专家与你合营商量容器技巧实践! 所谓边沿数据中间,指的就是:处于>>>详细阅读
本文标题:iOS开发3年只用5分钟搞定面试官
地址:http://www.17bianji.com/lsqh/40950.html
1/2 1