I have a class called BackendConnector that uses NSURLConnection to call SoapWebservice , which is https. I found a lot of messages and tried to implement the Authentication Methods delegate, but they won’t be called and after 6 hours in google I won’t get what I did wrong. Can someone please give me a hint why these 2 delegate methods will not be called? I set a breakpoint in each, started my application with Xcode in the simulator, but still get an error, and the breakpoints do not get there.
BackendConnector.m #import "BackendConnector.h" @implementation BackendConnector @synthesize dataPoint, chartDataPoints; - (NSMutableArray *)GetWebserviceData { NSMutableData *myMutableData; chartDataPoints = [[NSMutableArray alloc] init]; [self createWebserviceAndGetResponse: &myMutableData]; if (myMutableData != NULL) { NSString *theXml = [[NSString alloc]initWithBytes:[myMutableData mutableBytes] length:[myMutableData length] encoding:NSUTF8StringEncoding]; NSLog(@"doc = %@", theXml); arrayCount = 0; [self parseResponse: myMutableData]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"There is no Data returned from Webservice!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; [alert release]; } return NULL; //return chartDataPoints; } - (void) createWebserviceAndGetResponse: (NSMutableData **) myMutableData_p { NSMutableString *sRequest = [[NSMutableString alloc]init]; [sRequest appendString:@"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.ReportWebservice.xyz.com/\">"]; [sRequest appendString:@"<soapenv:Header/>"]; [sRequest appendString:@"<soapenv:Body>"]; [sRequest appendString:@"<ser:getReport>"]; [sRequest appendString:@"<arg0>User/arg0>"]; [sRequest appendString:@"<arg1>password</arg1>"]; [sRequest appendString:@"</ser:getReport>"]; [sRequest appendString:@"</soapenv:Body>"]; [sRequest appendString:@"</soapenv:Envelope>"]; NSURL *myWebserverURL = [NSURL URLWithString:@"https://xyz.com/services/report"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myWebserverURL]; NSLog(@"request: %@", request); [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [request addValue:@"" forHTTPHeaderField:@"SOAPAction"]; NSString *contentLengthStr = [NSString stringWithFormat:@"%d", [sRequest length]]; [request addValue:contentLengthStr forHTTPHeaderField:@"Content-Length"]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]]; NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if(conn) { *myMutableData_p=[[NSMutableData data] retain]; } [NSURLConnection connectionWithRequest:request delegate:self]; NSError *WSerror; NSURLResponse *WSresponse; *myMutableData_p = [NSURLConnection sendSynchronousRequest:request returningResponse:&WSresponse error:&WSerror]; } - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; } - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; } @end
Error:
Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be "xyz.com" which could put your confidential information at risk." UserInfo=0x8161600 {NSErrorFailingURLStringKey=https:
Many thanks
twickl
source share