-1

I have this code the I find on youtube xD my question is, how do I add an extra parameter?

 NSData *imageData = UIImageJPEGRepresentation(imagen.image,0.0);
 NSString *urlString = @"http://urlexample.com/upload.php";
 NSMutableURLRequest *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: application/octet-stream\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];

 NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
 NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

 NSLog(returnString);

I try

[body appendData:[[NSString stringWithFormat:@"extra=%@",info] dataUsingEncoding:NSUTF8StringEncoding];

hehehe im 100% new on this as you can see. please help me xD

Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
Sammaeliv
  • 11
  • 1

1 Answers1

1

I recently came across this earlier thread, and I think what you're looking for is something like this to add a field called foo and set it to bar:

[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"foo\"\r\n\r\nbar\n"]]];
Community
  • 1
  • 1
Joost Schuur
  • 4,417
  • 2
  • 24
  • 39
  • yes someting like that but for some reason didnt work, i make a print_r($_POST) on php file to nslog the response and showme Array(); – Sammaeliv Jun 09 '10 at 19:28