在不适用第三方框架的情况下,使用Swift提供的API进行网络操作
1、NSURLConnection
/**
通过NSURLConnection对象发送同步请求
使用同步操作,该方法不支持,废弃
*/
func sendSynchronousRequest() {
// 1、创建请求路径
let url = NSURL(string: uri)!;
// 2、创建请求对象。NSURLRequest方法默认为GET请求
// let request = NSURLRequest(URL: url);
// 2、创建可变的NSURLRequest对象
let request = NSMutableURLRequest(URL: url);
// 设置超时时间
request.timeoutInterval = 3;
// 3、通过NSURLConnection对象发送请求(同步请求)
let data = NSURLConnection.sendSynchronousRequest(request, returningResponse: nil, error: nil)!;
}
/**
通过NSURLConnection对象发送异步请求
*/
func se