同步Get方式
// MARK: - 同步Get方式 func synchronousGet() { //创建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 response:NSURLResponse? //错误对象 var error:NSError? //发出请求 var data:NSData? = NSURLConnection.sendSynchronousRequest(urlRequest, returningResponse: &response, error: &error) if (error != nil) { println(error?.code) println(error?.description) }else { var jsonString = NSString(data: data!, encoding: NSUTF8StringEncoding) println(jsonString) } }