1
Xcode 놀이터에서 매우 간단한 RESTful API GET 요청을 시도했지만 인증서 오류가 발생했습니다. 오류없이 우편 배달부의HTTPS JSON 데이터 구문 분석 오류이 서버의 인증서가 유효하지 않습니다.
2014-09-28 18:27:39.075 JSON Parse[7009:1766181] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807)
API error: Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.googleapis.com” which could put your confidential information at risk." UserInfo=0x7f9e73a04fe0 {NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x7f9e714391a0>, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9807, NSErrorPeerCertificateChainKey=<CFArray 0x7f9e71700070 [0x103794970]>{type = immutable, count = 3, values = (
0 : <cert(0x7f9e71437710) s: *.googleapis.com i: Google Internet Authority G2>
1 : <cert(0x7f9e71437e50) s: Google Internet Authority G2 i: GeoTrust Global CA>
2 : <cert(0x7f9e71438810) s: GeoTrust Global CA i: Equifax Secure Certificate Authority>
)}, NSUnderlyingError=0x7f9e73805310 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.googleapis.com” which could put your confidential information at risk.", NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.googleapis.com” which could put your confidential information at risk., NSErrorFailingURLKey=https://www.googleapis.com/books/v1/volumes?q=programming, NSErrorFailingURLStringKey=https://www.googleapis.com/books/v1/volumes?q=programming, NSErrorClientCertificateStateKey=0}, Optional([NSURLErrorFailingURLPeerTrustErrorKey: <SecTrustRef: 0x7f9e714391a0>, NSLocalizedRecoverySuggestion: Would you like to connect to the server anyway?, NSErrorFailingURLKey: https://www.googleapis.com/books/v1/volumes?q=programming, NSErrorFailingURLStringKey: https://www.googleapis.com/books/v1/volumes?q=programming, NSErrorPeerCertificateChainKey: <__NSCFArray 0x7f9e71700070>(
<cert(0x7f9e71437710) s: *.googleapis.com i: Google Internet Authority G2>,
<cert(0x7f9e71437e50) s: Google Internet Authority G2 i: GeoTrust Global CA>,
<cert(0x7f9e71438810) s: GeoTrust Global CA i: Equifax Secure Certificate Authority>
)
, NSErrorClientCertificateStateKey: 0, NSLocalizedDescription: The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.googleapis.com” which could put your confidential information at risk., _kCFStreamErrorDomainKey: 3, NSUnderlyingError: Error Domain=kCFErrorDomainCFNetwork Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.googleapis.com” which could put your confidential information at risk." UserInfo=0x7f9e738055a0 {NSErrorFailingURLStringKey=https://www.googleapis.com/books/v1/volumes?q=programming, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFNetworkCFStreamSSLErrorOriginalValue=-9807, kCFStreamPropertySSLPeerCertificates=<CFArray 0x7f9e71700070 [0x103794970]>{type = immutable, count = 3, values = (
0 : <cert(0x7f9e71437710) s: *.googleapis.com i: Google Internet Authority G2>
1 : <cert(0x7f9e71437e50) s: Google Internet Authority G2 i: GeoTrust Global CA>
2 : <cert(0x7f9e71438810) s: GeoTrust Global CA i: Equifax Secure Certificate Authority>
)}, _kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x7f9e714391a0>, NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.googleapis.com” which could put your confidential information at risk., _kCFStreamErrorDomainKey=3, NSErrorFailingURLKey=https://www.googleapis.com/books/v1/volumes?q=programming, _kCFStreamErrorCodeKey=-9807}, _kCFStreamErrorCodeKey: -9807])
fatal error: unexpectedly found nil while unwrapping an Optional value
API 호출 작동하고 브라우저 : 나는 오류가
import UIKit
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely()
let url = NSURL(string:"https://www.googleapis.com/books/v1/volumes?q=programming")
let urlReq = NSURLRequest(URL: url)
let queue = NSOperationQueue()
NSURLConnection.sendAsynchronousRequest(urlReq, queue: queue, completionHandler: { (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
if (error != nil) {
println("API error: \(error), \(error.userInfo)")
}
var jsonError:NSError?
var json:NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonError) as NSDictionary
if (jsonError != nil) {
println("Error parsing json: \(jsonError)")
}
else {
println(json)
}
})
: 여기 내 코드입니다. Google에서 유효한 SSL 인증서를 가지고 있다고 가정합니다. 아무도 내가 왜이 오류를, 그리고 더 imprtantly, 어떻게 그것을 막을 수 있는지 알 수 있습니까.