This is part of my code... I didn't post it here because it is a bit long, lol.
What I was trying to do is that, I try to grab user input (from a UITextField) and display it in the screen (by a UITextView). After that, I grab the .text value from the UITextView, convert it from NSString to NSData, then upload the NSData object to a HTTP server, with a php upload script.
NSString *completeName = [NSString stringWithFormat:@"%@/%@.txt",mainDelegate.gCourseCode,mainDelegate.gUID];
NSString *finalWordList = wordList.text;
NSData *data = [finalWordList dataUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = @"http://cetl.no-ip.org:50080/upload.php";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n",completeName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:data]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(returnString);
The txt file can be uploaded to the server. But it misses the \n character.
Thank you very much for your help.