Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Alamofire HTTPS请求失败_Ios_Swift_Alamofire - Fatal编程技术网

Ios Alamofire HTTPS请求失败

Ios Alamofire HTTPS请求失败,ios,swift,alamofire,Ios,Swift,Alamofire,我想在我的swift应用程序中使用Alamofire,从服务器获取数据。但当我通过Alamofire发送请求时,它总是抛出一个错误。但是如果我使用默认配置的NSUrlSession,它就可以工作了 我尝试了这个解决方案,但仍然不起作用 我正在使用的代码 let headers = [ "Authorization": validationHeader ] let completeUrl = kReserveBaseURL + strMyResURL Al

我想在我的swift应用程序中使用Alamofire,从服务器获取数据。但当我通过Alamofire发送请求时,它总是抛出一个错误。但是如果我使用默认配置的NSUrlSession,它就可以工作了

我尝试了这个解决方案,但仍然不起作用

我正在使用的代码

let headers = [
        "Authorization": validationHeader
    ]

    let completeUrl = kReserveBaseURL + strMyResURL
    Alamofire.request(.GET, completeUrl, headers: headers)
        .response { request, response, data, error in
            debugPrint(error)
            debugPrint(response)
    }
下面是我得到的问题

    Some : Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “abc.xyz.com” which could put your confidential information at risk." UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x7ff0c22052d0>, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9813, NSErrorPeerCertificateChainKey=<CFArray 0x7ff0c044b840 [0x10996ba40]>{type = immutable, count = 2, values = (
    0 : <cert(0x7ff0c22044c0) s: abc.xyz.com i: Verizon Public SureServer EV SSL CA G14-SHA2>
    1 : <cert(0x7ff0c2204770) s: Verizon Public SureServer EV SSL CA G14-SHA2 i: Cybertrust Global Root>
)}, NSUnderlyingError=0x7ff0c2302070 {Error Domain=kCFErrorDomainCFNetwork Code=-1202 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x7ff0c22052d0>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9813, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9813, kCFStreamPropertySSLPeerCertificates=<CFArray 0x7ff0c044b840 [0x10996ba40]>{type = immutable, count = 2, values = (
    0 : <cert(0x7ff0c22044c0) s: abc.xyz.com i: Verizon Public SureServer EV SSL CA G14-SHA2>
    1 : <cert(0x7ff0c2204770) s: Verizon Public SureServer EV SSL CA G14-SHA2 i: Cybertrust Global Root>
)}}}, NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “abc.xyz.com” which could put your confidential information at risk., NSErrorFailingURLKey=https://abc.xyz.com/Api/CheckIn/GetData?userId=0&BookingDate=2016-04-16, NSErrorFailingURLStringKey=https://abc.xyz.com/Api/CheckIn/GetData?userId=0&BookingDate=2016-04-16, NSErrorClientCertificateStateKey=0}
Some:Error Domain=NSURLErrorDomain code=-1202“此服务器的证书无效。您可能正在连接假装为“abc.xyz.com”的服务器,这可能会使您的机密信息面临风险。”UserInfo={NSURlerErrorFailingUrlPeerTrustErrorKey=,NSLocalizedRecoverysSuggestion=是否仍要连接到服务器?,kCFStreamErrorDomainKey=3,kCFStreamErrorCodeKey=-9813,NSErrorPeerCertificateChainKey={type=不可变,计数=2,值=(
0 : 
1 : 
)},NSUnderlyingError=0x7FF0C230270{Error Domain=KCFerrorDomain=KCF网络代码=-1202“(null)”用户信息={{kCFStreamPropertySSLClientCertificateState=0,kCFStreamPropertySSLPeerTrust=,KCFnetworkCfsstreamsLerOriginalValue=-9813,kCFStreamErrorDomainKey=3,kCFStreamErrorCodeKey=-9813,kCFStreamPropertySSLPeerCertificates={type=不可变,count=2,value=(
0 : 
1 : 
)}}},NSLocalizedDescription=此服务器的证书无效。您可能正在连接假装为“abc.xyz.com”的服务器这可能会使您的机密信息处于危险之中,。n错误失败密钥=https://abc.xyz.com/Api/CheckIn/GetData?userId=0&BookingDate=2016-04-16,NSERRORFAILLINGURSTRINGKEY=https://abc.xyz.com/Api/CheckIn/GetData?userId=0&BookingDate=2016-04-16,NSErrorClientCertificateStateKey=0}

由于iOS安全限制(SSL级别的不可信服务器证书),您似乎遇到了此错误。我建议您通过在应用程序的信息列表中添加安全异常来解决此问题。plist:

<key>NSAppTransportSecurity</key>
<dict>
    <!--Include to allow all connections (DANGER)-->
    <key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads
源链接:

添加此项后,您不应再观察错误。

如果有帮助,您可以使用以下方法计算depper:


与您特别相关的部分是:“使用nscurl工具诊断ATS连接问题”

这是因为存在安全限制。在info.plist中添加这两条注释,

我可以看到您用于满足请求的代码片段吗?