views:

716

answers:

4

I downloaded apple's demo for using HTTP POST and GET (Their sample app has a tabbar with different parts) and the code is so confusing!

Could anybody give me some sample code or a link to some tutorials about it? :)

Thanks!

A: 

There're a lot of tutorials around the Web. Just Google it. For example: http://deusty.blogspot.com/2006/11/sending-http-get-and-post-from-cocoa.html

beefon
+1  A: 

This walkthrough by Matt Long is particularly good: http://www.cimgf.com/2010/02/12/accessing-the-cloud-from-cocoa-touch/

Dirk Stoop
A: 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] 
        initWithURL:[NSURL 
        URLWithString:@"http://www.cimgf.com/testpost.php"]];
 
[request setHTTPMethod:@"POST"];
[request setValue:@"text/xml" 
              forHTTPHeaderField:@"Content-type"];
 
NSString *xmlString = @"<data><item>Item 1</item><item>Item 2</item></data>";
 
[request setValue:[NSString stringWithFormat:@"%d",
        [xmlString length]] 
        forHTTPHeaderField:@"Content-length"];
 
[request setHTTPBody:[xmlString 
        dataUsingEncoding:NSUTF8StringEncoding]];
 
[[NSURLConnection alloc] 
        initWithRequest:request 
                   delegate:self];
yasirmturk
A: 

Check out this article, it has a clear explanation of what you need

http://www.eigo.co.uk/iPhone-Submitting-HTTP-Requests.aspx

Eigo