I have been using a single part http post form in my objective C to upload data to a server (PHP), and then a separate multipart post form to upload the files.
I have just decided to consolidate it into a single, multipart form for various reasons.
However, when using exactly the same objc on iPhone (meaning when I NSLog out what I am sending, it is percent encoded the same in both ways in doing it), and exactly the same php on the server I have realised that somehow the percent encoded strings lose their percent encoding along the way in the single part form, whereas with the multipart form the percent encoding is retained.
In the single part form the relevant section is like this:
params =[NSString stringWithFormat:@"string=%@", PERCENT_ENCODED_STRING];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
If I NSLog out params the encoding is there.
Whereas in the multipart form the relevant section is like this
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; //boundary of post data section
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: text/plain; name=%@\r\n", @"string"] dataUsingEncoding:NSUTF8StringEncoding]]; //dataname
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; //blank line
[body appendData:[PERCENT_ENCODED_STRING dataUsingEncoding:NSUTF8StringEncoding]]; //actual data
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; //end of line
...
[request setHTTPMethod:@"POST"];
[request setHTTPBody:body];
The php is exactly the same in each case.
Has anyone come across this before?
I'm very aware that I could just be doing something stupid, but I've been looking at this all day without being able to figure out what is going on.
thanks in advance