调用HTTPS Soap服务时出现NSURLConnection错误
我试图从Soap请求获取数据,但得到我的应用程序崩溃与此错误:
2016-02-08 11:12:11.524 Example[567:128898] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9843) Response: nil fatal error: unexpectedly found nil while unwrapping an Optional value
我在plist中启用了安全设置,并成功调用其他服务。
注:该服务是在HTTPS上,我得到这个错误,因为这个? 这是否需要任何证书?
我第一次打电话给肥皂服务,也请指导我如何在服务中添加电子邮件参数:( https:// [IP]:9897 / JLIPolicyinfo.asmx?op = GetEmail_Poldetail )
这里是我从这里得到的代码:( 使用SOAP的IOS Swift调用Web服务 )
let is_SoapMessage: String = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cgs=\"http://www.cgsapi.com/\"><soapenv:Header/><soapenv:Body><cgs:GetSystemStatus/></soapenv:Body></soapenv:Envelope>" let is_URL: String = "https://58.27.241.203:9897/JLIPolicyinfo.asmx" let lobj_Request = NSMutableURLRequest(URL: NSURL(string: is_URL)!) let session = NSURLSession.sharedSession() let err: NSError? lobj_Request.HTTPMethod = "POST" lobj_Request.HTTPBody = is_SoapMessage.dataUsingEncoding(NSUTF8StringEncoding) lobj_Request.addValue("58.27.241.203", forHTTPHeaderField: "Host") lobj_Request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type") lobj_Request.addValue(String((is_SoapMessage.characters.count)), forHTTPHeaderField: "Content-Length") //lobj_Request.addValue("223", forHTTPHeaderField: "Content-Length") lobj_Request.addValue("http://tempuri.org/GetEmail_Poldetail", forHTTPHeaderField: "SOAPAction") let task = session.dataTaskWithRequest(lobj_Request, completionHandler: {data, response, error -> Void in print("Response: \(response)") let strData = NSString(data: data!, encoding: NSUTF8StringEncoding) print("Body: \(strData)") if error != nil { print("Error: " + error!.description) } }) task.resume()
这是我的plist补充:
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSExceptionDomains</key> <dict> <key>https://58.27.241.203:9897/JLIPolicyinfo.asmx</key> <dict> <key>NSIncludesSubdomains</key> <false/> <key>NSExceptionAllowInsecureHTTPSLoads</key> <false/> <key>NSExceptionRequiresForwardSecrecy</key> <true/> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.2</string> <key>NSThirdPartyExceptionAllowInsecureHTTPSLoads</key> <false/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <true/> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.2</string> <key>NSRequiresCertificateTransparency</key> <false/> </dict> </dict> </dict>
您可能有一个自签名证书,也可能是一个问题。
解决scheme: –如果您续订您的服务器的ssl证书以使用SHA2并启用TLS v1.2,则它将起作用。
可能是一个解决scheme: –你必须在你的info.plist文件中添加它,以便它可以允许不安全的连接: –
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
甚至你可以像这样添加:
编辑:-
在你的info.plist中添加这个特定的exception。
<key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>testdomain.com</key> <dict> <key>NSIncludesSubdomains</key> <false/> <key>NSExceptionAllowInsecureHTTPSLoads</key> <false/> <key>NSExceptionRequiresForwardSecrecy</key> <true/> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.2</string> <key>NSThirdPartyExceptionAllowInsecureHTTPSLoads</key> <false/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <true/> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.2</string> <key>NSRequiresCertificateTransparency</key> <false/> </dict> </dict> </dict>
- 如何使用AFNetworking比较SSL证书
- SSL身份证书在iOS上运行HTTPS服务器
- 使用MonoTouch,HttpClient和Charles Proxy时出现HTTPstream量监控问题
- NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813)iOS
- Uber API端点不能与真正的服务器域一起工作,但可以很好地与沙箱配合使用
- Delphi 10.1 Berlin idHTTP / IPv6 / iOS / Socket错误#51networking无法访问
- 我如何configurationWireshark来查看HTTPSstream量?
- 使用NSURLConnection连接到具有自签名证书的https时,kSecTrustResultRecoverableTrustFailure
- 在iOS中,如何使用https在服务器上使用自签名证书连接到服务器?