Tôi cố gắng để tiêu thụ đảm bảo dịch vụ yên tĩnh mang đến cho lỗiiphone: máy chủ restfull an toàn "Giấy chứng nhận cho máy chủ này là không hợp lệ
Lỗi = Lỗi miền = NSURLErrorDomain Mã = -1202" Giấy chứng nhận cho máy chủ này không hợp lệ . Bạn có thể đang kết nối với máy chủ giả vờ là “xxx.xxx.xxx.xxx” có thể khiến thông tin bí mật của bạn gặp rủi ro. ”
làm việc trên xCode 4.2, lỗi hoặc bất kỳ bước nào bị thiếu.
sử dụng đoạn mã sau
RegisterUser.f
@interface RegisterUser : UIViewController<UITextFieldDelegate,
UIScrollViewDelegate, NSURLConnectionDelegate>
RegisterUser.m
- (IBAction)SubmitBtnAction:(id)sender {
NSURL *url = [NSURL URLWithString:@"https://xx.xx.xx.xxx:8223/jaxrs/tunedoorgateway/getCountries"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if ([data length] >0 && error == nil)
{
NSLog(@"Data = %@", data);
// DO YOUR WORK HERE
}
else if ([data length] == 0 && error == nil)
{
NSLog(@"Nothing was downloaded.");
}
else if (error != nil){
NSLog(@"Error = %@", error);
}
}];
}
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
NSLog(@"This is canAuthenticateAgainstProtectionSpace");
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
// if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
// if ([trustedHosts containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
NSLog(@"This is didReceiveAuthenticationChallenge");
// [[challenge sender] cancelAuthenticationChallenge:challenge];
}
Tôi sẽ giải quyết vấn đề này bằng cách đặt ngày và giờ thích hợp cho thiết bị của tôi. – Hemang
Giải quyết cùng một vấn đề với chỉ thiết lập ngày và giờ của thiết bị thành tự động. –