Currently I am consuming a soap web service using block in ios my source code is as follows
NSString *xml = requestXMLToSent;
NSString *msgLength = [NSStrin
I assume you use https scheme in your serviceURL and your test server has problems with SSL certificate. If so and you trust it, implement next methods in your NSURLConnection
delegate's:
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if([challenge.protectionSpace.host isEqualToString:@"127.0.0.1"] /*check if this is host you trust: */ )
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
To have a delegate initialize your NSURLConnection
for example with initWithRequest:delegate:startImmediately:
method.
Check your delegates are actually being called.
This documentation explains that your delegates may not be getting called in certain circumstances.
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html
Important: The URL loading system classes do not call their delegates to handle request challenges unless the server response contains a WWW-Authenticate header. Other authentication types, such as proxy authentication and TLS trust validation do not require this header.
Server is throwing SSL certificate error.
For the sake of testing, you can add the following code to the appDelegate:
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host {
return YES;
}
This will bypass the SSL error
Note: works for NSURLConnection & UIWebView, but not for WKWebView
Edited:
For iOS 9, above procedure don't work. Add the following snippet in info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
In iOS 9.0 add the following to info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>