iOS开发——网络编程Swift篇&(四)异步Get方式
2024-08-25 04:57:46
异步Get方式
// MARK: - 异步Get方式 func asynchronousGet() { //创建NSURL对象 var url:NSURL! = NSURL(string: "http://m.weather.com.cn/data/101010100.html") //创建请求对象 var urlRequest : NSURLRequest = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: ) //连接服务器 var connection = NSURLConnection(request: urlRequest, delegate: self) } // MARK: - NSURLConnectionDelegate : NSObjectProtocol { func connection(connection: NSURLConnection, didFailWithError error: NSError) { //请求失败 } func connectionShouldUseCredentialStorage(connection: NSURLConnection) -> Bool { //连接应使用证书存储 return true } func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { //发送请求验证 } func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool { //可以验证的保护空间 return true } func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { //获得认证 } func connection(connection: NSURLConnection, didCancelAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { //取消认证 }
最新文章
- Get-FilewithExtension
- c#动态加载卸载DLL的方法
- Unity发送参数给iOSNative并响应
- Objective-c---分类 、 扩展 、 ARC
- 【BZOJ】【1025】【SCOI2009】游戏
- 【英语】Bingo口语笔记(38) - See系列
- Linux系统github使用
- 利用ADO方式连接SQLServer2008出现的问题
- Sublime text2 常用插件集锦
- Solr4.8.0源码分析(25)之SolrCloud的Split流程
- WEB工程数据库相关安装脚本写作
- openGL线s的绘制
- apollo实现c#与android消息推送(三)
- 这是我对GET与POST的区别的回答
- jsz中的作用域与上下文
- vxWorks6.6 N270 D525 cpu的bsp配置总结
- 学习任务,阅读一下Redis分布式锁的官方文档
- oracle 12C版本的下载安装
- python import引入不同路径下的模块
- Grafana 监控系统是否重启
热门文章
- Android 中屏幕点击事件的实现
- http://jingyan.baidu.com/article/4dc40848e7b69bc8d946f127.html
- 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(6)
- UITextView 不左上角显示
- Multiple View Geometry in Computer Vision Second Edition by Richard Hartley 读书笔记(一)
- 获取本机外网IP的方式笔记
- 仿酷狗音乐播放器开发日志二十四 选项设置窗体的实现(附328行xml布局源码)
- qt 获取天气的接口
- wuzhicms访问统计实现方法
- <;问题>;Eclipse中Deploy应用到GAE的错误