You would want to use an NSURLConnection with a NSMutableURLRequest, something like this:
NSMutableURLRequest *theRequest=[[NSMutableURLRequest alloc] init];
[theRequest addValue:@"attachment;filename=\"file2.gif\"" forHTTPHeaderField:@"Content-disposition"];
[theRequest addValue:@"image/gif" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"binary" forHTTPHeaderField:@"Content-Transfer-Encoding"];
[theRequest setHttpBody:myBodyNSDataObject];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
You can modify or set headers using the NSMutableURLRequest method:
- (void)addValue:(NSString *)value forHTTPHeaderField:(NSString *)field
The response will be whatever the server comes back with. You can check out Apple's documentation for the rest of the delegate methods to implement to get the body of the response back. You should have the NSData object representing the content of the file you want to upload ready. Doing the same using FTP is a bit more involved, but this will work to post the file body up. You will want to make sure your NSData object is set up like the body of an HTTP post, such that you set up the headers like:
[theRequest addValue:@"attachment;filename=\"file2.gif\"" forHTTPHeaderField:@"Content-disposition"];
[theRequest addValue:@"image/gif" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"binary" forHTTPHeaderField:@"Content-Transfer-Encoding"];
And then you should append the body. On the server side, you can get the file name and the bytes composing the file.
This is not exactly the code you should use, but it should give you a good idea of how to proceed.