NSURL *url = [NSURL URLWithString:@"https://myUrlString.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *responseurl;
NSError *err;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseurl error:&err];
NSLog(@"data length:%u", data.length);
NSLog(@"response:%@ , error:%@", responseurl, err);
,我得到的迴應是: -在https上的GET錯誤?無法設置NSLocalizedRecoverySuggestion
data length:0
response:(null) ,
錯誤:錯誤域= NSURLErrorDomain代碼= -1202「此服務器的證書無效,您可能正在連接到。假裝成「myUrlString.com」的服務器可能會使您的機密信息處於危險之中。「的UserInfo = {0x8742d70 = NSErrorFailingURLStringKey HTTPS:HTTPS://myUrlString.com,
NSLocalizedRecoverySuggestion =你想連接到反正服務器?
NSErrorFailingURLKey = HTTPS://myUrlString.com,
NSLocalizedDescription =此服務器的證書無效。您可能正在連接到一個僞裝成「myUrlString.com」,這可能會危害您的機密信息的服務器,NSUnderlyingError = 0x8745bf0「The certificate for this server is invalid. You might be connecting to a server that is pretending to be 「myUrlString.com」 which could put your confidential information at risk.
」,NSURLErrorFailingURLPeerTrustErrorKey =}
也許'ASIHTTPRequest'可以解決這個問題(它受到更長時間的支持,所以這可能沒有什麼問題),但是正如你在這裏概述的那樣,創建和配置'NSMutableURLRequest'肯定不會。您必須明確地響應'NSURLSession' /'NSURLConfiguration'認證方法,或者您必須調用禁止此驗證的私有方法。 – Rob 2014-03-26 16:58:53