简体   繁体   English

iOS NSURLConnection sendSynchronousRequest错误地报告HTTPS站点的SSL证书错误

[英]iOS NSURLConnection sendSynchronousRequest incorrectly reports SSL certificate error for HTTPS sites

The following iOS playground snippet: 以下iOS游乐场代码段:

import UIKit

// let urlPath = "http://ip.jsontest.com"
let urlPath = "https://api.github.com/repos/vmg/redcarpet"

var url = NSURL(string: urlPath)

var request: NSURLRequest = NSURLRequest(URL: url!)

var response: NSURLResponse?

var error: NSError?

var dataVal =  NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error:&error)

if error == nil {
    println(response)
} else {
    println(error)
}

Correctly prints the response for the HTTP url, but says that the HTTPS url has a certificate error. 正确打印HTTP URL的响应,但是说HTTPS URL有证书错误。 I've tried three different sites that I know have valid certificates. 我尝试了三个我知道有有效证书的站点。 Any idea what's wrong? 知道有什么问题吗?

It looks like this is an iOS playground bug. 看来这是一个iOS游乐场错误。 In an OSX playground, both URLs work, and both work in a real iOS app. 在OSX游乐场中,两个URL均有效,并且在真实的iOS应用中均有效。 So, this is apparently just a playground issue. 因此,这显然只是一个操场问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM