I'm trying to upload an image file to a http server. Here's the code fragment
NSData *imgData = UIImagePNGRepresentation(img);
NSString *post = [NSString stringWithFormat:@"&UserID=%@&Query=%@&fileContent=", userID, @"putImage"];
NSMutableData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[postData appendBytes:[imgData bytes] length:imgData_len];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSURL *url = [NSURL URLWithString:@"http://ryan.verifyidonline.com/test.php"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
This code only sends the first few characters of the image file. I think I have to encode the file somehow, but I haven't had any luck trying the NSString encodings.