alamofire简单使用
1. alamofire简单文件网络请求,并处理。
// ViewController.swift
// alamofire测试
//
// Created by amesty on 15/5/30.
// Copyright (c) 2015年 cf. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//通常情况下,您只需将请求对象链接到响应方法上.
//responseJSON()方法。当网络请求完毕后,responseJSON()方法会调用我们所提供的闭包。在我们的示例中,我们只是简单的将经过解析的 JSON 输出到控制台中。
//· 调用responseJSON方法意味着您期望获得一个 JSON 数据。在我们的示例中,Alamofire 试图解析响应数据并返回一个 JSON 对象。或者,您可以使用responsePropertyList来请求获得一个属性列表,也可以使用responseString来请求获得一个初始字符串。在本教程后面,您将了解更多关于响应序列化方法的使用方式。
request(.GET,"http://localhost/demo.json").responseJSON() { (_, _, JSON, _) -> Void in
println(JSON)
}
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func demo1(){
// · Alamofire.request(_:_)接收两个参数:method和URLString。其中,method 通常是.GET、.POST;URLString通常是您想要访问的内容的 URL。其将返回一个Alamofire.Request对象。
request(.GET, "http://ww.baidu.com", parameters: nil, encoding: .URL).responseString(encoding: NSUTF8StringEncoding) { (_, _, html, error) -> Void in
if error != nil {
println(error)
return
}
println(html)
}
}
}
转载于:https://my.oschina.net/u/150265/blog/422640
- Swift - Alamofire简单GET和POST使用
- SWIFT闭包,介绍,使用(ALAMOFIRE封装 异步请求)
- iOS 使用 AFNetwork && Alamofire 实时监测网络状况
- <iOS>Alamofire的使用
- Alamofire 的使用
- 使用cocopods安装Alamofire后各种报错
- Swift - 不使用pods如何正确添加类似Alamofire这样的库
- Hangfire下载安装与简单使用
- Alamofire的使用教程
- swift网络请求工具Alamofire 的使用
- Swift - Alamofire - GET/POST/upload 的使用
- AlamofireObjectMapper框架的基本使用以及二次封装
- Swift&NodeJS 使用Alamofire进行Post(zhuan)
- Alamofire源码解读系列(一)之概述和使用
- iOS 使用 Alamofire 实时监测网络状况
- 学以致用-使用Spotfire创建自己的简单知识库查询系统
- PHP在浏览器上跟踪调试的方法以及使用ChromePhp、FirePHP的简单介绍
- Xampp+Openfire+Spark的简单使用
- ios--学习Alamofire网络框架的使用
- PHP在浏览器上跟踪调试的方法以及使用ChromePhp、FirePHP的简单介绍