如何在主线程下面执行帖子?
var post:String = "fname=\(addy)&lname=\(fff)&time=\(ff)&action=\(sd_asds)&actionid=add&content=\(d)".stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
是否可能在主线程上运行帖子会导致内存警告?
答案 0 :(得分:0)
为了发送POST请求,您可以使用NSURLConnection类,该类具有发送请求asyncrhonously
的方法,这意味着它将执行"关闭主线程"。
示例:
var post:String = "fname=\(addy)&lname=\(fff)&time=\(ff)&action=\(sd_asds)&actionid=add&content=\(d)".stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
var postURL: NSURL = NSURL(string: post)
let request: NSURLRequest = NSURLRequest(URL:postURL)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler:{ response, data, error in
//your code here
})
<强>文档强>