//
// ViewController.swift
// AlamFireDemo
//
// import UIKit
import Alamofire class ViewController: UIViewController {
lazy var defManager : Manager = {
//1、get addtional http header
var defHeaders = Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders ?? [:]
//2、set a NSURLSessionConfiguration
let conf = NSURLSessionConfiguration.defaultSessionConfiguration()
conf.HTTPAdditionalHeaders = defHeaders //3、geneter a manager
let manager = Alamofire.Manager(configuration: conf)
return manager }()
// 后台下载
lazy var backgroundManager :Manager = { var defHeaders = Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders ?? [:] let conf = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("com.example.app.backgroud")
let manager = Alamofire.Manager(configuration: conf)
return manager
}() lazy var ephemeralManager :Manager = { var defHeaders = Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders ?? [:] let conf = NSURLSessionConfiguration.ephemeralSessionConfiguration()
let manager = Alamofire.Manager(configuration: conf)
return manager
}()
override func viewDidLoad() {
super.viewDidLoad()
Alamofire.request(.GET, "https://httpbin.org/get").response { (request, response, data, error) -> Void in
print(request)
print(response)
print(data)
print(data.dynamicType)
print(error)
print(error.dynamicType)
}.responseString { (response) -> Void in
print("String ==========")
switch response.result {
case .Success(let str):
print("\(str.dynamicType)")
print("\(str)")
case .Failure(let error):
print("\(error)") }
}.responseJSON { (response) -> Void in
print("JSON ==========") switch response.result { case .Success(let json):
let dic = json as! Dictionary<String,AnyObject> let origin = dic["origin"] as! String
let headers = dic["headers"] as! Dictionary<String,String>
print("origin :\(origin)")
print("user-agent :\(headers["User-Agent"])")
case .Failure(let error):
print(error)
}
}
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }

1、创建AlamFireDemo 工程,关闭工程
2、进入到工程目录 执行 pod init 命令 生成 PodFile文件
3、vi PodFile编辑该文件

启用:platform :ios, '8.0'

use_frameworks!

在end之前粘贴 pod 'Alamofire','~> 3.0’,执行pod install
4、安装完成之后打开白色工程
open -a Xcode AlamoFireDemo.xcworkspace

  

AlamoFireDemo的更多相关文章

  1. 【swift学习笔记】四.swift使用Alamofire和swiftyJson

    Alamofire是AFNetworking的swift版本,功能灰常强大. github:https://github.com/Alamofire/Alamofire SwiftyJSON是操作js ...

  2. Swift使用Alamofire实现网络请求

    Alamofire是一个用Swift编写的HTTP网络库,由此前热门开源项目AFNetworking的的作者mattt开发,可非常简单地用于异步网络通信. 要获取最新版本的 Alamofire,前往h ...

  3. Alamofire请求网络

    HTTP - GET和POST请求- 如果要传递大量数据,比如文件上传,只能用POST请求- GET的安全性比POST要差些,如果包含机密/敏感信息,建议用POST- 如果仅仅是索取数据(数据查询), ...

  4. 基于LBS平台的iOS开发

    LBS,即Location Based Services,基于位置服务,用于定位.导航等功能,比如地图应用.订外卖等的app就需要这个功能. 在这里我使用的是高德LBS开放平台,地址:http://l ...

  5. 命令行添加pod示例

    1.创建AlamFireDemo 工程,关闭工程 2.进入到工程目录 执行 pod init 命令 生成 PodFile文件 3.vi PodFile编辑该文件 启用:platform :ios, ' ...

  6. Swift之分割视图控制器-UISplitViewController

    Swift之分割视图控制器-UISplitViewController UISplitViewController这种控制器只能用于iPad,它可以在iPad屏幕中显示两个不同的场景:在横向模式下,左 ...

随机推荐

  1. 嵌入式Linux上通过boa服务器实现cgi/html的web上网【转】

    转自:http://blog.csdn.net/tianmohust/article/details/6595996 版权声明:本文为博主原创文章,未经博主允许不得转载. 嵌入式Linux上通过boa ...

  2. Optional int parameter 'rows' is not present but cannot be translated into a null value due to being declared as a primitive type.

    我的spring mvc 代码: @Controller @RequestMapping("/product") public class Fancy { @RequestMapp ...

  3. dll共享段中一些需要注意的问题

    Visual C++ 如何与应用程序或其他 DLL 共享自己 DLL 中的数据? Win32 DLL 映射到调用进程的地址空间中.默认情况下,每个使用 DLL 的进程都有自己的所有 DLL 全局变量和 ...

  4. POJ 1189 钉子和小球

    题目链接:http://poj.org/problem?id=1189 dp 可以知道一共有2^n条路径,则设顶点有2^n个球,若当前为'*'则向左右的球各有一半:若为'.',则球全部掉入正下方. # ...

  5. js-获取用户移动端网络类型:wifi、4g、3g、2g...

    今天工作时间很宽裕, 忽然想起,自己做过的所有页面中,有些页面经常会面临用户在网络状态很差的时候打开页面,页面是挂了的状态,感觉很LOW~. 所以我决定在今后的页面中我需要先判断用户的网络状态, 若是 ...

  6. Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException

    Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException reason:JDK与Scala的版本不 ...

  7. kong的preserve_host和strip_uri解析

    preserve_host:当代理的时候,k代理时,Kong的默认行为是将上游请求的Host头设置为API的upstream_url属性的主机名.这个参数接受一个boolean值. 当为FALSE时, ...

  8. 第八章 android-布局

    常用的布局实现方式:线性布局,框架布局,表格布局,相对布局,绝对布局 1,线性布局 (1)线性布局是一种很重要的布局,也是经常用到的一种布局 (2)在线性布局中,所有的元素都按照水平竖直的顺序在界面上 ...

  9. 集合框架(05)Collections

    1.Collections.sort方法(以及自定义的比较字符串长度排序) package Collections; import java.util.*; class StrLenComparato ...

  10. 如何隐藏 Safari 中 input 标签的 autofill 图标

    Safari 浏览器会为 <input type="passport"> 标签自动添加一个小锁的图标(如下图),本意上是让用户可以从这里选择相应的 用户名/密码 进行自 ...