我正在尝试使用我的应用程序与服务器建立 HTTPS 连接。但是由于以下错误,连接失败
错误域=NSURLErrorDomain 代码=-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];
}
我被困在这里,找不到任何出路。
任何形式的帮助将不胜感激。
提前致谢!!