ios - 通过POST方法发送带有其他参数的图像
ios - Send image with other parameters by POST method
我已经编写了一个代码来按用户在网络中添加项目并且它工作正常..现在我想添加另一个参数,即图像..我无法这样做..我的代码是
NSString *posturslString= [NSString stringWithFormat:@"ToDo_Item=%@&ToDo_Date=%@&AddedBy=%i",self.ToDo_Item, [dateformatter stringFromDate:self.ToDo_Date],self.AddedBy];
NSString *postData = [[NSString alloc] initWithString:posturslString];
[request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response = [[NSURLResponse alloc] init];
self.receivedData =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSError * error;
NSDictionary *user = [NSJSONSerialization JSONObjectWithData:self.receivedData
options:0
error:&error];
NSNumber *successNumber = [user objectForKey:@"success"];
success = [successNumber integerValue];
我如何发送图像,即 nsdata
NSData *png=UIImagePNGRepresentation(self.itemImage.image);
连同我的其他参数。请帮忙
将图像转换为 base64Encoded
NSData *imageData = UIImageJPEGRepresentation(uploadImage, 1.0);
NSString *base64String = [imageData base64EncodedStringWithOptions:kNilOptions];
NSString *encodedString2 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( NULL, (CFStringRef)base64String, NULL, CFSTR("!*'();:@&=+$,/?%#[]\" "), kCFStringEncodingUTF8));
并添加与其他关键字相同的图片
NSString *posturslString= [NSString stringWithFormat:@"ToDo_Item=%@&ToDo_Date=%@&AddedBy=%i&image=%@",self.ToDo_Item, [dateformatter stringFromDate:self.ToDo_Date],self.AddedBy,encodedString2];
注意:- 还需要在服务器端实现图像的转换 base64Encoded
我已经编写了一个代码来按用户在网络中添加项目并且它工作正常..现在我想添加另一个参数,即图像..我无法这样做..我的代码是
NSString *posturslString= [NSString stringWithFormat:@"ToDo_Item=%@&ToDo_Date=%@&AddedBy=%i",self.ToDo_Item, [dateformatter stringFromDate:self.ToDo_Date],self.AddedBy];
NSString *postData = [[NSString alloc] initWithString:posturslString];
[request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response = [[NSURLResponse alloc] init];
self.receivedData =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSError * error;
NSDictionary *user = [NSJSONSerialization JSONObjectWithData:self.receivedData
options:0
error:&error];
NSNumber *successNumber = [user objectForKey:@"success"];
success = [successNumber integerValue];
我如何发送图像,即 nsdata
NSData *png=UIImagePNGRepresentation(self.itemImage.image);
连同我的其他参数。请帮忙
将图像转换为 base64Encoded
NSData *imageData = UIImageJPEGRepresentation(uploadImage, 1.0);
NSString *base64String = [imageData base64EncodedStringWithOptions:kNilOptions];
NSString *encodedString2 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( NULL, (CFStringRef)base64String, NULL, CFSTR("!*'();:@&=+$,/?%#[]\" "), kCFStringEncodingUTF8));
并添加与其他关键字相同的图片
NSString *posturslString= [NSString stringWithFormat:@"ToDo_Item=%@&ToDo_Date=%@&AddedBy=%i&image=%@",self.ToDo_Item, [dateformatter stringFromDate:self.ToDo_Date],self.AddedBy,encodedString2];
注意:- 还需要在服务器端实现图像的转换 base64Encoded