Ios 如何将UIImage或NSData转换为字节数组并发布到服务器?

Ios 如何将UIImage或NSData转换为字节数组并发布到服务器?,ios,post,bytearray,nsdata,asiformdatarequest,Ios,Post,Bytearray,Nsdata,Asiformdatarequest,如何将UIImage或NSDate转换为字节数组并发布到服务器。 在我的应用程序中,我必须将UIImage转换为字节数组,然后发布 对于post,我使用asASIFormDataRequest 我的代码是: NSUInteger len = [self.dataImage length]; Byte *byteData= (Byte*)malloc(len); //converting date to byte array [self.dataImage getBytes:byteDat

如何将
UIImage
NSDate
转换为字节数组并发布到服务器。 在我的应用程序中,我必须将
UIImage
转换为字节数组,然后发布

对于post,我使用as
ASIFormDataRequest

我的代码是:

NSUInteger len = [self.dataImage length];
 Byte *byteData= (Byte*)malloc(len);  //converting date to byte array
 [self.dataImage  getBytes:byteData length:len];


 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlStr]];
  [request setRequestMethod:@"POST"];


 [request addData:self.dataImage withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];
 [request setDelegate:self];
 [request startAsynchronous];
试着这样,

    NSData *imageData = UIImagePNGRepresentation(self.dataImage ,0.1);
 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlStr]];
  [request setRequestMethod:@"POST"];


 [request addData:imageData withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];
 [request setDelegate:self];
 [request startAsynchronous];

我用替换的方法解决了这个问题

         [request addData:imageData withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];

可能重复的
       [request appendPostData:self.dataImage];