3

I've managed to get simple text data sent to a server using this code:

NSMutableString *parameterString = [[NSMutableString alloc] initWithString: @""];
[parameterString appendString:@"name=steve&"];
[parameterString appendString:@"surname=jobs&"];
[parameterString appendString:@"age=55"];
NSURL *url = [NSURL URLWithString:@"http://example.come/script/"];
request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
NSData *parameterData = [parameterString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:parameterData];

With that I can send text form data. But how can I send PNG images as well?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
cannyboy
  • 24,180
  • 40
  • 146
  • 252

2 Answers2

1

You could just convert the image to an NSData object, then base64 encode it to send it as a parameter.

Base64 encoding examples found here: How do I do base64 encoding on iphone-sdk?

Community
  • 1
  • 1
Brad
  • 11,262
  • 8
  • 55
  • 74
0
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addData:imageData withFileName:@"image.png" andContentType:@"image/png" forKey:@"yourParamKey"];
saurb
  • 685
  • 1
  • 13
  • 24