这是我的代码崩溃的部分:
let bodyData = "username=" + username + "&password=" + password
let URL: NSURL = NSURL(string: "URL OF A PHP FILE")!
let request:NSMutableURLRequest = NSMutableURLRequest(URL:URL)
request.HTTPMethod = "POST"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) // Crashes here !
{
(response, data, error) in
var output = NSString(data: data, encoding: NSUTF8StringEncoding)
[Rest of the code]
}
错误是:
fatal error: unexpectedly found nil while unwrapping an Optional value
我认为是 NSURLConnection.sendAsynchronousRequest 导致我的应用程序崩溃,因为我已经调试了我的应用程序并且它在那里崩溃了
这是请求的值:
<NSMutableURLRequest: 0x14d55b70> { URL: [URL OF PHP FILE] }
而且我知道数据变量不是零