Skip to content

Commit

Permalink
Support self-signed SSL Certificate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit Riessen committed Jul 19, 2011
1 parent d04d4ee commit 4707350
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions CCMenu/Classes/CCMConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ @implementation CCMConnection
- (id)initWithURL:(NSURL *)theServerUrl
{
[super init];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[theServerUrl host]];
serverUrl = [theServerUrl retain];
return self;
}

- (id)initWithURLString:(NSString *)theServerUrlAsString
{
return [self initWithURL:[NSURL URLWithString:theServerUrlAsString]];
NSURL *url = [NSURL URLWithString:theServerUrlAsString];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
return [self initWithURL:url];
}

- (void)dealloc
Expand All @@ -35,19 +38,19 @@ - (id)delegate

- (NSString *)errorStringForError:(NSError *)error
{
return [NSString stringWithFormat:@"Failed to get status from %@: %@",
return [NSString stringWithFormat:@"Failed to get status from %@: %@",
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey], [error localizedDescription]];
}

- (NSString *)errorStringForResponse:(NSHTTPURLResponse *)response
{
return [NSString stringWithFormat:@"Failed to get status from %@: %@",
return [NSString stringWithFormat:@"Failed to get status from %@: %@",
[response URL], [NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]]];
}

- (NSString *)errorStringForParseError:(NSError *)error
{
return [NSString stringWithFormat:@"Failed to parse status from %@: %@ (Maybe the server is returning a temporary HTML error page instead of an XML document.)",
return [NSString stringWithFormat:@"Failed to parse status from %@: %@ (Maybe the server is returning a temporary HTML error page instead of an XML document.)",
[serverUrl description], [[error localizedDescription] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}

Expand Down Expand Up @@ -82,8 +85,8 @@ - (void)requestServerStatus
if(urlConnection != nil)
return;
NSURLRequest *request = [NSURLRequest requestWithURL:serverUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
if((urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]) == nil)
[NSException raise:@"ConfigurationException" format:@"Cannot create connection for URL [%@]", [serverUrl absoluteString]];
if((urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]) == nil)
[NSException raise:@"ConfigurationException" format:@"Cannot create connection for URL [%@]", [serverUrl absoluteString]];
receivedData = [[NSMutableData data] retain];
}

Expand Down

0 comments on commit 4707350

Please sign in to comment.