Yesterday the HTTPs certificate was installed on my server, where my webservice is running. Before the HTTPs certificate was installed, my self-made iPhone app sent a SOAP request to the webservice. The webservice succesfully answered by returning an XML message.
This is the code which I use for sending the soap request to the webservice:
NSString *soapMsg = [NSString stringWithFormat:@""
""
""
""
"%@"
"%@"
""
""
"", parameter1, parameter2];
NSURL *url = [NSURL URLWithString:
@"http://domain.com/webservice-name.svc"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",
[soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/webservice-name/method-name" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *resultsData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
if(error){
NSLog(@"Error sending soap request: %@", error);
return FALSE;
}
NSLog(@"%@", soapMsg);
NSLog(@"%@", [[NSString alloc] initWithData:resultsData encoding:NSUTF8StringEncoding]);
Now if I change the URL to "httpS://domain.com/webservice-name.svc", the webservice doesn't repsonse at all.
What do I have to change to send a succesfull SOAP request to a HTTPS secured webservice?
For normal xml service using GET method https request was working for me. Try this delegate methods that I have used.`
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSArray *trustedHosts=[NSArray arrayWithObject:@"yourdomian.com"];
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
if ([trustedHosts containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With