同步GET

发布时间:2020-04-10 00:21:09 作者:缘起愿落
来源:网络 阅读:287



创建get请求,

1.将网址初始化成一个OC字符串对象.
NSString * urlString = [NSString stringWithFormat:@"%@?query=%@&region=%@&output=json&ak=6E823f587c95f0148c19993539b99295",kBusinessInfoURL,@"银行",@"济南"];
     如果网址中存在中文,进行转码

    NSString * urlString = @"http://p_w_picpath.zcool.com.cn/56/13/1308200901454.jpg";

    NSString * newURLString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 

2.构建网络URL对象
    NSURL * url = [NSURL URLWithString:newURLString];
    //3.创建网络请求
    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
  

3.创建同步连接.
    NSURLResponse * response = nil;
    NSError * error = nil;
    NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
   

4.解析

    NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSLog(@"%@",dic);

推荐阅读:
  1. rsync远程同步(定期同步,实时同步实战!)
  2. rsync远程同步中的定期同步和实时同步怎么用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

同步 get et

上一篇:Unity3D静态对象优化系列三

下一篇:用绿色打造新一代数据中心

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》