调用HTTPS Soap服务时出现NSURLConnection错误 [英] Geting NSURLConnection error while calling HTTPS Soap service

查看:188
本文介绍了调用HTTPS Soap服务时出现NSURLConnection错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Soap请求获取数据,但让我的应用程序因此错误而崩溃:

  2016-02-08 11:12:11.524示例[567:128898] NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9843)
响应:nil
致命错误:在解包可选值时意外发现nil

我已在plist中启用安全设置并成功调用其他服务。



注意:该服务是在HTTPS上,我是否因此而收到此错误?这是否需要任何证书?



我是第一次拨打肥皂服务,请指导我如何在服务中添加电子邮件参数:(



编辑: -



在info.plist中添加此内容以了解具体例外情况。

 < 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>


I am trying to get data from Soap request but getting my app crashed with this error:

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

I have enabled Security settings in plist and calling other services successfully.

Note: The service is on HTTPS, am i getting this error because of this? is this required any certificate?

i am calling soap service for the first time, please also guide me on how to add email parameter in service: (https://[IP]:9897/JLIPolicyinfo.asmx?op=GetEmail_Poldetail)

here is my code that i get from here: (IOS Swift Call Web Service using SOAP)

        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()

Here is my plist addition:

<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>

解决方案

You might have a self signed certificate that can be also a problem .

Solution:- It will work if you renew your server's ssl certificate to use SHA2 and enabling TLS v1.2.

Possibly a solution:- You have to add this in your info.plist file, so that it can allow non-secure connection:-

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Or even you can add like this:-

Edit:-

Add this in your info.plist for specific 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>

这篇关于调用HTTPS Soap服务时出现NSURLConnection错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆