I have a iPhone app that has a queue of pictures to upload to a web server. The question is: How to create a IBAction to stop the uploads? Here's a snippet of my code:
NSMutableURLRe开发者_高级运维quest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: binary\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
Thanks, Coulton!
I believe that this will answer all your questions and more :)
http://allseeing-i.com/ASIHTTPRequest/How-to-use
It contains heaps of information, heaps of examples and uses Asyncrhonous so that your UI isn't blocked. Further down the page it talks about sending data exactly like what you want to do, but I suggest read from the top as it will talk you through other things taht are important.
精彩评论