ios - Geting NSURLConnection error while calling HTTPS Soap service -
i trying data soap request getting app crashed 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 optional value
i have enabled security settings in plist , calling other services successfully.
note: service on https, getting error because of this? required certificate?
i calling soap service first time, please guide me on how add email parameter in service: (https://[ip]:9897/jlipolicyinfo.asmx?op=getemail_poldetail)
here code 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 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 self signed certificate can problem .
solution:- work if renew server's ssl certificate use sha2 , enabling tls v1.2.
possibly solution:- have add in info.plist file, can allow non-secure connection:-
<key>nsapptransportsecurity</key> <dict> <key>nsallowsarbitraryloads</key> <true/> </dict>
or can add this:-
edit:-
add in info.plist 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>
Comments
Post a Comment