Nasir Khan February 2016

Geting NSURLConnection error while calling HTTPS Soap service

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_        

Answers


Vizllx February 2016

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

enter image description here

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>

Post Status

Asked in February 2016
Viewed 1,789 times
Voted 9
Answered 1 times

Search




Leave an answer