ios 异步后台获取网络资源
2015-10-13 22:16
609 查看
ios9下面https 配置
控制台打印的部分结果:
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
- (void)testNetWork { <span style="color:#ff0000;">//后台方式下获取网络资源 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{</span> NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]; NSError *error; NSString *data = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error]; if (data != nil) { <span style="color:#ff0000;"> 主线程中重新刷新界面UI dispatch_async(dispatch_get_main_queue(), ^{</span> NSLog(@"%@",data); }); } else { NSLog(@"---------%@",error); } }); }
控制台打印的部分结果:
2015-10-13 22:11:29.070 CommonDemo[21656:298955] <!DOCTYPE html><!--STATUS OK--><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><meta content="always" name="referrer"><meta name="theme-color" content="#2932e1"><link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /><link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索" /><link rel="icon" sizes="any" mask href="//www.baidu.com/img/baidu.svg"><link rel="dns-prefetch" href="//s1.bdstatic.com"/><link rel="dns-prefetch" href="//t1.baidu.com"/><link rel="dns-prefetch" href="//t2.baidu.com"/><link rel="dns-prefetch" href="//t3.baidu.com"/><link rel="dns-prefetch" href="//t10.baidu.com"/><link rel="dns-prefetch" href="//t11.baidu.com"/><link rel="dns-prefetch" href="//t12.baidu.com"/><link rel="dns-prefetch" href="//b1.bdstatic.com"/><title>百度一下,你就知道</title>
相关文章推荐
- 解决TCP网络传输“粘包”问题
- 项目开发之网络连接和数据库
- 第三方判断网络状态
- Android网络通信框架Volley总结
- https://pypi.python.org/pypi/ssh
- URL编码表/HTTP消息含义
- Reachability(判断网络是否连接)
- Android访问https链接
- yum源码编译安装http
- 《TCP/IP详解 卷一》读书笔记-----第三章 IP
- 更新Xcode7后网络请求数据问题?
- Swift 原生网络通信
- 神经网络&深度学习
- TCP的拥塞控制
- 《网络编程》先进 I/O
- 类神经网络的角点检测方法
- linux0.99网络模块-网络模块初始化
- NCRE三级网络技术考试——八,九月总结
- 有关http的内容
- [Java]Http报文详解