i have two function recordsound and post this recorded sound to the server.
this is the following code i used to post to the server
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"recordedTmpFile" ofType:@"caf"];
NSURL *file =[[NSURL alloc] initFileURLWithPath:filePath];
NSString *filepath = [[NSBundle mainBundle] initWithContentsOfURL:recordedTmpFile];
NSData *postData = [NSData dataWithContentsOfFile:filePath];
//nsdata to string
NSString* newStr = [NSString stringWithUTF8String:[postData bytes]];
//http post
NSMutableString *jsonRequest = [[NSMutableString alloc]init];
[jsonRequest appendString:newStr];
NSURL *url = [NSURL URLWithString:@"http address"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];
[NSURLConnection connectionWithRequest:[request autorelease] delegate:self];
I am using ASIHTTPRequest‘s library. It has a setFile: method to allow you posting a file to the server.