var url:NSURL=NSURL(string:"http://xxxxxxxx/index.php?s=/Public_verify.html")!
var data:NSData=NSData(contentsOfURL: url)!
var img:UIImage=UIImage(data:data)!
self.Verify.setBackgroundImage(img, forState: UIControlState.Normal)
var username=UserName.text
var password=PassWord.text
var verifycode=VerifyCode.text
let url=NSURL(string:"http://xxxxxxxx/index.php?s=/Public_doLogin.html")!
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
let postString = "username=\(username)&password=\(password)&verifyCode=\(verifycode)&ajax=1"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
//cookie?
}
task.resume()
上面的代码,我使用了NSURLSession.sharedSession()。 DataTaskWithRequest到POST登录。 我退出APP,COOKIE消失需要重新登录 除非我注销用户,否则如何记录cookie?