Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

beachdog

macrumors member
Original poster
Aug 10, 2008
86
0
Currently I'm having to construct the multi-part body myself (see example code below). I'm surprised that there isn't an easier way to do this...or is there?

Code:
/* construct body of the request */
NSString* boundary = [NSString stringWithString:@"---28461D3FG"];
NSMutableData* data = [NSMutableData data];
[data appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSASCIIStringEncoding]];
[data appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"subscriberid\"\r\n\r\n%@",strSubId] dataUsingEncoding:NSASCIIStringEncoding]];
[data appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSASCIIStringEncoding]];
[data appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"greetingid\"\r\n\r\n%@",strGreetingId] dataUsingEncoding:NSASCIIStringEncoding]];
/* ...etc */

NSURL* url = [NSURL URLWithString:@"http://216.41.17.74/uploaGreetingRequest.jsp"];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [data length]]  forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:data];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.