gpt4 book ai didi

通过 iPhone 连接到服务器时出现 SSL 错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:37:46 24 4
gpt4 key购买 nike

我正在尝试使用我的应用程序与服务器建立 HTTPS 连接。但是由于以下错误导致连接失败

Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo=0x612eb30 {NSErrorFailingURLStringKey=https:myURL.com/signup, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSErrorFailingURLKey=https:myURL.com/signup, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSUnderlyingError=0x612eb70 "An SSL error has occurred and a secure connection to the server cannot be made."}

连接服务器的代码是

-(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];
}
}

我的委托(delegate)方法是

- (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];
}

我被困在这里,找不到任何出路。

我们将不胜感激任何形式的帮助。

提前致谢!!

最佳答案

iOS 9 强制使用 HTTPS 的连接为 TLS 1.2 以避免最近的漏洞。在 iOS 8 中甚至支持未加密的 HTTP 连接,因此旧版本的 TLS 也不会产生任何问题。作为解决方法,您可以将此代码片段添加到您的 Info.plist 中:

  <key>NSAppTransportSecurity</key>  
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

因此,您将禁用 App Transport Security。希望对您有所帮助。

关于通过 iPhone 连接到服务器时出现 SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5040531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com