2016-02-05 63 views
0

我製作了一個運行https網站的服務器。我想在Xcode的控制檯上打印出網站的信息。在控制檯打印一個網站的信息

爲了做到這一點,我添加了以下到我的ViewController.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSError *error; 
    NSString *address = [NSString stringWithFormat: @"https://54.169.239.78:3001"]; 
    NSURL *url = [NSURL URLWithString:address]; 
    NSString *theWeb = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error]; 
    NSLog(@"%@", theWeb); 
} 

然而,結果總是(null)。此外,我得到一個錯誤:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)

即使我已經允許應用程序傳輸安全性在我的Info.plist

有什麼不對?

+0

記錄'錯誤'並查看問題是什麼。 – rmaddy

+0

請參閱[這些搜索結果](http://stackoverflow.com/search?q=%5Bios%5D+kCFStreamErrorDomainSSL+%22-9813%22)。它可能與您的服務器上的SSL證書有關。 – rmaddy

+0

您正在使用自簽名證書嗎? – CaptJak

回答

0

問題僅限於您的證書。如果你已經像這樣正確設置了你的plist。 enter image description here

如果你想驗證這件事情只是改變了網站的URL(https://developer.apple.com/)在你的代碼和更新代碼:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    NSError *error; 
    NSString *address = [NSString stringWithFormat: @"https://developer.apple.com/"]; 
    NSURL *url = [NSURL URLWithString:address]; 
    NSString *theWeb = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error]; 
    NSLog(@"%@", theWeb); 
} 

我已經試過這一點,已經顯示的內容。

你實際上需要真正的SSL證書。這裏是有關細節和自簽名證書的證書鏈接也已在此處進行了討論: Certificate details