我正在尝试使用我的应用程序与服务器建立HTTPS连接。但由于以下错误,连接失败了:
Error Domain=NSURLErrorDomain Code=-1200 "发生SSL错误,无法建立到服务器的安全连接。" UserInfo=0x612eb30 {NSErrorFailingURLStringKey=https:myURL.com/signup, NSLocalizedRecoverySuggestion=您是否仍要连接到服务器?, NSErrorFailingURLKey=https:myURL.com/signup, NSLocalizedDescription=发生SSL错误,无法建立到服务器的安全连接。, NSUnderlyingError=0x612eb70 "发生SSL错误,无法建立到服务器的安全连接。"}
连接服务器的代码是:
-(IBAction) handleEvents:(id)sender
{
if ((UIButton*)sender == submit) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSLog(@"Begin");
NSData *urlData;
NSURLResponse *response;
NSError *error;
NSString *url =[[NSString alloc]initWithFormat:@"%@signup",baseURL];
NSURL *theURL =[NSURL URLWithString:url];
NSMutableURLRequest *theRequest =[NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0.0f];
[theRequest setHTTPMethod:@"POST"];
NSString *theBodyString = [NSString stringWithFormat:@"emailId=%@&mobileNumber=%@&appId=%@&password=%@&firstName=%@&lastName=%@"
,@"abc@example.com",@"919879876780",@"bf1c7a6b3d266a7fe350fcfc4dda275211c13c23" ,@"qwerty" , @"Dev" , @"Sri"];
NSData *theBodyData = [theBodyString dataUsingEncoding:NSUTF8StringEncoding];
[theRequest setHTTPBody:theBodyData];
urlData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
}
}
我的代理方法是
- (void)handleError:(NSError *)error
{
NSLog(@"----->%@",error);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge (NSURLAuthenticationChallenge *)challenge {
NSLog(@"check auth");
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
我卡在这里了,找不到任何解决方法。
非常感谢任何形式的帮助。
提前致谢!!