dev*_*sri 32 ssl https nsurlconnection nsurlrequest
我正在尝试使用我的应用程序建立到服务器的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];
}
}
Run Code Online (Sandbox Code Playgroud)
我的委托方法是
- (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];
}
Run Code Online (Sandbox Code Playgroud)
我被困在这里,无法找到任何出路.
任何形式的帮助将不胜感激.
提前致谢!!
Vod*_*Ion 43
iOS 9强制使用HTTPS的连接为TLS 1.2以避免最近的漏洞.在iOS 8中,甚至支持未加密的HTTP连接,因此旧版本的TLS也没有出现任何问题.作为解决方法,您可以将此代码段添加到Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
因此,您将禁用App Transport Security.希望这很有帮助.
| 归档时间: |
|
| 查看次数: |
43330 次 |
| 最近记录: |