Connect to untrusted SSL servers on iPhone

by alex 29. September 2010 02:30

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *) space {

if([[space authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust]) {

// Note: this is presently only called once per server (or URL?) until

//       you restart the app

if(shouldAllowSelfSignedCert) {

return YES; // Self-signed cert will be accepted

} else {

return NO// Self-signed cert will be rejected

}

}

return NO;

}

 

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {

return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];

Get cookies using iPhone SDK

by alex 14. May 2009 09:44

NSHTTPURLResponse * response;

NSError * error;

NSMutableURLRequest *request;

request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://google.com/"]

cachePolicy:NSURLRequestReloadIgnoringCacheData 

timeoutInterval:60] autorelease];

NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

 

NSLog(@"%@", [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]);

NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@"http://google.com/"]];

NSLog(@"%d", all.count);

 

for (NSHTTPCookie *cookie in all) {

NSLog(@"Name: %@ : Value: %@", cookie.name, cookie.value); 

}

 

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen