1

重複の可能性:
HTTP 基本認証に NSURLCredentialStorage を使用できますか?

自己署名サーバー証明書を受け入れるにはどうすればよいですか? 以下のコードを使用すると、Safari を使用してサーバー証明書を受け入れた後にのみ接続/認証できます。

- (void)secure:(NSString *)username credentials:(NSString *)login
{
  NSURLCredential *userCredentials = [NSURLCredential credentialWithUser:username
                                                                password:login
                                                             persistence:
                                                        NSURLCredentialPersistenceForSession];

  NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc] initWithHost:LIST_URL_HTTPS
                                                                      port:443
                                                                   protocol:@"https"
                                                                     realm:@"Restricted Area"
                                                      authenticationMethod:NSURLAuthenticationMethodHTTPBasic];

  [[NSURLCredentialStorage sharedCredentialStorage] setCredential:userCredentials
                                               forProtectionSpace:space];


  NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:imageURL]
                                                            cachePolicy:NSURLCacheStorageNotAllowed
                                                        timeoutInterval:30];

  NSURLResponse *response;
  NSError *error;

  NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest
                                             returningResponse:&response
                                                         error:&error];

}
4

0 に答える 0