views:

79

answers:

1

Hi

I am writing an iPhone App and I need to securely send an XML request and receive it ALL securely. I think I did it right I just want some confirmation that the below code is all secure. Thanks.

NSURL *url = [NSURL URLWithString: @"https://secure.site.com/request"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = [NSString stringWithFormat:@"%d", [xml length]];

[req addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [xml dataUsingEncoding:NSUTF8StringEncoding]];

conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; if (conn) webData = [[NSMutableData data] retain];

and in the connectionDidFinishLoading..

    - (void) connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *gotXml = [[NSString alloc] 
                    initWithBytes: [webData mutableBytes] 
                    length:[webData length] 
                    encoding:NSUTF8StringEncoding];

Thanks

+1  A: 

Yes, so long as the URL has https:// in it, the request will be sent securely.

Mike
Assuming the certificates are all valid...
mopoke
The message will be sent securely if there is a certificate installed. Whether the certificate is current, expired or self-signed, the https protocol still encrypts the data.
Tim