// Created by Alexandre Colucci on 23/07/2008.
// Copyright 2008 Alexandre Colucci. All rights reserved.
// Dummy interface to avoid a warning.
@interface NSURLRequest (DummyInterface)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
@end
@implementation MainController
-(IBAction)doSomething:(id)sender
{
// The URL of the Webserver
NSURL *myWebserverURL = [NSURL URLWithString:@"https://myWebserver.com/"];
// Create the request
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:myWebserverURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
// Set the HTTP method.
[theRequest setHTTPMethod:@"POST"];
// Set useful headers
[theRequest setValue:@"text/xml" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/xml" forHTTPHeaderField:@"Content-type"];
// The body
NSString *theDataString = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?><something></something>";
NSData *theData = [theDataString dataUsingEncoding:NSUTF8StringEncoding];
[theRequest setHTTPBody:theData];
// Use the private method setAllowsAnyHTTPSCertificate:forHost:
// to not validate the HTTPS certificate.
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[myWebserverURL host]];
// Create the NSURLConnection and init the request.
[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
}