Alamofire playground example breaks with HTTPS URL in version 1.2.1

自古美人都是妖i 提交于 2019-12-13 19:30:48

问题


Edited:

I originally thought this was due to an OS update, but evidently it was an unintentional update to the latest version of Alamofire, 1.2.3, and that exposed authentication changes in Alamofire made in 1.2.1.

My test case is just the shipping Alamofire playground file (as of 1.2.1-3), with the single change to the https URL: https://example.com (and to print the error):

import XCPlayground
import Foundation
import Alamofire

println("start")

// Allow network requests to complete
XCPSetExecutionShouldContinueIndefinitely()

Alamofire.request(.GET, "https://example.com/", parameters: nil)
         .responseString { (request, response, string, error) in
            println(error)
            println(request)
            println(response)
            println(string)
         }
    .response() { request, response, data, error in

        println("\(response)")
}

println("end")

With that change, I get the following result:

2015-07-03 19:08:04.984 Alamofire[8080:1003896] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807) Optional(Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “example.com” which could put your confidential information at risk." UserInfo=0x7fd1b35834e0 {NSURLErrorFailingURLPeerTrustErrorKey=, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorCodeKey=-9807, NSUnderlyingError=0x7fd1b370b2e0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1202.)", NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “example.com” which could put your confidential information at risk., NSErrorFailingURLKey=https://example.com/, NSErrorFailingURLStringKey=https://example.com/, _kCFStreamErrorDomainKey=3}) { URL: https://example.com/ }

Am I missing something - is there more I need to do to connect to an https URL, or is this just an oversight? I did read the Alamofire Readme but nothing jumped out at me for an immediate solution.

It is really easy to reproduce just change the default URL in the Alamofire playground to any URL that uses HTTPS (example.com seemingly the most canonical)

Thanks!

来源:https://stackoverflow.com/questions/31216242/alamofire-playground-example-breaks-with-https-url-in-version-1-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!