My iPad app sends a list of files as a string parameter, fileList
to a web method like this:
NSString *post = [NSString stringWithFormat:@"sessionID=%@&fileList=%@&dateTime=%@&userID=%@", sessionID, fileList, timeOpened, userID];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *comparisonURLString = SERVER_COMPARE_URL_STRING;
NSURL *comparisonURL = [NSURL URLWithString:comparisonURLString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:comparisonURL];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
[request setHTTPMethod:@"POST"];
[request addValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
When the list of files is above a certain size, it seems to be truncated. I couldn't find anything about a maximum size in the apple documentation. Also, the subsequent parameters seem to be received OK regardless but before I discount this as a possible source of the problem, I was wondering if anyone knows if there is such a limitation?
The server is running IIS7, and the webConfig maxRequestLength
is set to 1048576.
-EDIT-
Source of the Problem:
I created a webmethod that only takes in the entire POST
as a parameter and it removes everything after an ampersand (&) so I think this may be where the problem lies, rather than parameter size.
I think the issue might be a missing Content-Type
HTTP Request header field:
[request setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
Also use UTF-8 to encode the payload:
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];