我一直在試圖找出什麼是錯的白衣我的代碼,但我不斷收到這個錯誤在SWIFT 2.0雨燕2.0 URL POST請求
Errors thrown from here are not handled because the enclosing catch is not exhaustive
的自動轉換,從XCode中做了很多工作,爲我(也給了很多錯誤),但這仍然不起作用。我不明白什麼是工作,所以也許你們可以對案件提出一些看法。在此先感謝
這裏是我的代碼
if config.isConnected() {
let post:NSString = "postID=\(postID)"
//NSLog("PostData: %@",post);
let url:NSURL = NSURL(string:"https://www.example.com/json/index.php")!
let postData:NSData = post.dataUsingEncoding(NSASCIIStringEncoding)!
let postLength:NSString = String(postData.length)
let 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("application/json", forHTTPHeaderField: "Accept")
var reponseError: NSError?
var response: NSURLResponse?
var urlData: NSData?
do {
urlData = try NSURLConnection.sendSynchronousRequest(request, returningResponse:&response) // gives error
} catch let error as NSError {
print(reponseError)
reponseError = error
urlData = nil
}
if (urlData != nil) {
Webiew.loadRequest(request)
} else {
let alert: UIAlertView = UIAlertView(title: "OOPS", message: "There is nothing here!", delegate: nil, cancelButtonTitle: "OK");
alert.show()
}
} else {
// not connected
}
幾乎沒有,只有一個警告,我無法擺脫掉, contentBodyAsString = contentBodyAsString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! 不推薦使用'stringByAddingPercentEscapesUsingEncoding':改爲使用stringByAddingPercentEncodingWithAllowedCharacters(_ :),它始終使用推薦的UTF-8編碼,並對特定的URL組件或子組件進行編碼,因爲每個URL組件或子組件對於哪些字符有效。 從xcode提出的解決方案不起作用 –
同樣在這裏,對我來說它的工作,但有相同的警告。所以我沒有太注意這一點。任何機會你可以打開關於這個新的線程? –
它的粉碎或它劑量甚至得到迴應? –