試試這個: -
var url:NSURL = NSURL(string: "http://www.example.com")!
var postData:NSData = post.dataUsingEncoding(NSASCIIStringEncoding)!
var postLength:NSString = String(postData.length)
var request:NSMutableURLRequest = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.HTTPBody = postData
//request.setValue(postLength as String, forHTTPHeaderField: "Content-Length")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.setValue("*/*", forHTTPHeaderField: "Accept")
var reponseError: NSError?
var response: NSURLResponse?
var urlData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse:&response, error:&reponseError)
let res = response as! NSHTTPURLResponse!;
NSLog("Response code: %ld", res.statusCode);
檢查出UIWebViewDelegate的didFailLoadWithError – Gruntcakes
我想看看如果在webview中我獲得404,501錯誤等。 – ewan