Я хочу загрузить изображение в формате png на сервер. Мне нужно указать три параметра с запросом:
transactionID: (any random integer)
signatureBytes:data:image/png;base64,iVBORw0KGgoAAAsdffsdfsdfsdfsdfYAAAAeGRPoAAAgAElEQVR4nO2de5BmRXnGHzWmYkKVKUqJRk0erwerrwds55/lVnT/mm+87/Z4+3f30+/YN6D9L48CMA9VxnOJ9S
guid: CAD1CBE7-B5A4-43d6-BCDD-89B16F97E3C4
Я использовал код:
NSData *imageData = UIImageJPEGRepresentation(image.image,90);
// setting up the URL to post to
NSString *urlString=@"http://www.riverport.net/icalibur/dev/signature.ashx";
// setting up the request object now
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=\"transactionID\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[[NSString stringWithString:@"7" intva] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"signatureBytes\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"data:image/png;base64,iVBUaBCrFDXGSIECEXEFdUFEhEVAluXmsrrtrrttrrqddcsvrgergergg/YN6D9L4uozc5h+nsWsFhGSn88CWAAwqV2ynoz1qvJjYTmfCOk1QxJ0ANgHijoZDy8CMA9VxnOJ9S"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"guid\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"CHJ78G-B5A4-43d6-BCDD-CFG567FGJ"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"ipodfile.png\"\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]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];
NSString* returns= [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
//NSLog(@"body %@",stri);
// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(returnString);
иответ от сервера:
[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +201
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +66
[InvalidCastException: Conversion from string "����
У кого-нибудь есть идеи В чем может быть проблема. Я не знаю, правильно ли я это делаю.