I have a very annoying problem, which I'm trying to solve. I have an iPhone app that sends several forms of data to a server. The server-side processes the data and responds, with PHP. With small lengths of data this goes fine, but one of the requests is pretty large and this doesn't go so well. The requests seems well encoded, with the proper length, even the Content-Length header is set. Still I get an incomplete (literally chopped off) result in PHP.
Here's some code:
NSString *requestString = [NSString stringWithFormat:@"json=%@", [params JSONFragment], nil];
NSLog(@"%@", requestString);
NSLog(@"%u", [requestString length]);
NSData *requestData = [requestString dataUsingEncoding:NSUTF8StringEncoding];
//NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: strlen([requestString UTF8String])]; //[requestString UTF8String]
//NSData *requestData = [NSData dataWithBytes: requestString length: [requestString length]]; //[requestString UTF8String]
//NSData *requestData = [NSData dataWithBytes:[requestString UTF8String] length:[requestString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"https://radarromance.com/api/index.php"]];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: requestData];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setValue:[NSString stringWithFormat:@"%u", [requestString length], nil] forHTTPHeaderField:@"content-length"];
Consider the actual data to be a properly formatted JSON string, with a length of > 4000 characters. I ran a tiny test to see whether the NSData object had the correct length, and it has. On the iPhone side, I assume, all is fine.
The PHP side however shows only a part of the request, so it's incomplete. The post_max_size is 16M, which should be sufficient.
How is this possible? What can possibly be wrong? Any help here is greatly appreciated!
Kind regards,
Reinder