I'm developing an iPhone application and I need to send some information to an url from a textview and 2 texfields, using the HTTP POST method. (to, subject, message). How do I do it? I understand it is something with NSURLRequest
, but I didn't find anything that could actually help me. So if you could please include a clarifying code example, I would really appreciate it.
views:
60answers:
2
A:
Maybe you find
http://stackoverflow.com/questions/2071788/iphone-sending-post-with-nsurlconnection http://stackoverflow.com/questions/330060/problem-using-nsurlrequest-to-post-data-to-server
helpful.
VolkerK
2010-08-30 12:16:25
A:
I recently wrote a subclass of NSMutableURLRequest
to make form POSTing a lot easier. It's on github: http://github.com/davedelong/CHFormRequest
You use it like this:
#import "CHFormRequest.h"
CHFormRequest * r = [[CHFormRequest alloc] initWithURL:[NSURL URLWithString:@"http://example.com/myForm.php"]];
[r setValue:@"test" forFormField:@"field1"];
[r setFile:@"/Users/example/Desktop/myFile.txt" forFormField:@"file"];
NSHTTPURLResponse * response = nil;
NSError * error = nil;
NSData * d = [NSURLConnection sendSynchronousRequest:r returningResponse:&response error:&error];
[r release];
Dave DeLong
2010-08-30 18:58:29
thank you for your link, but I get 2 errors at compiling: error: 'kUTTagClassFilenameExtension' undeclared (first use in this function)ANDerror: 'kUTTagClassMIMEType' undeclared (first use in this function)Can you help please?
DanielaM
2010-09-02 07:26:18