HTTPGet("http://www.baidu.com") {
(data: String,error: String?) -> Void in
if error != nil {
println(error)
} else {
println(data)
}
}
func HTTPGet(url: String,callback: (String,String?) -> Void) {
var request = NSMutableuRLRequest(URL: NSURL(string: url)!)
HTTPsendRequest(request,callback)
}
func HTTPsendRequest(request: NSMutableuRLRequest,
callback: (String,arial; font-size:14px; line-height:21px"> let task = NSURLSession.sharedSession().dataTaskWithRequest(
request,arial; font-size:14px; line-height:21px"> {
data,response,error in
if error != nil {
callback("",error.localizedDescription)
} else {
callback(
Nsstring(data: data,encoding: NSUTF8StringEncoding)!,arial; font-size:14px; line-height:21px"> nil
)
}
})
task.resume()
}