2

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.

Robert
  • 5,278
  • 43
  • 65
  • 115

1 Answers1

2

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];
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • OK, then time to turn to the server. Are you able to *mimic* your POST request using some other technology in order to verify that the problem doesn't lie within the server? – trojanfoe Feb 28 '13 at 10:55
  • I'm able to enter the individual parameters locally on the server, although not the whole POST request. – Robert Feb 28 '13 at 10:56
  • You need to mimic the POST request elsewhere in order to rule-out a server issue. You might be barking up the wrong tree. – trojanfoe Feb 28 '13 at 10:58
  • 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. – Robert Feb 28 '13 at 12:15
  • I was indeed barking up the wrong tree. Some of the document titles contained ampersands. I wrote a little routine to change them to `and` on upload and that seems to have solved it. Thanks for your help. – Robert Mar 01 '13 at 11:33
  • 1
    @Robert Another approach is to run all your parameters through `[NSString stringByAddingPercentEscapesUsingEncoding:]` before adding them to the payload. – trojanfoe Mar 01 '13 at 11:40