目前我有:如何忽略Objective-C中的「無效」SSL證書?
NSArray* array = [NSArray arrayWithObjects:@"auth.login",@"username",@"password", nil];
NSData* packed_array = [array messagePack];
NSURL* url = [NSURL URLWithString:@"https://192.168.1.149:3790/api/1.0"];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
//Previously the below had changed by hostname.
//[request setValue:@"RPC Server" forHTTPHeaderField:@"Host"];
[request setValue:@"binary/message-pack" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d",[packed_array length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:packed_array];
NSURLResponse *response;
NSError *error;
responseData = [NSMutableData dataWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]];
NSLog(@"response data: %@",[responseData messagePackParse]);
NSLog(@"error: %@",error);
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
NSLog(@"called canAuthenticateAgainstProtectionSpace");
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSLog(@"called didReceiveAuthenticationChallenge");
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
它返回"Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid"…
「
我應該如何從this question和獲取數據回貫徹答案
DUP http://stackoverflow.com/questions/933331/how-to-use-nsurlconnection-to-connect-with-東西ssl-for-un-untrusted-cert – hamstergene
您是否忽略閱讀該問題? :^ \我無法實現該答案中的代碼。 – erran
您尚未發佈實例化NSURLConnection的代碼。你是否正確地將它委託給實現這兩種方法的對象? – Taum