Ios 将图像与文本一起保存在web服务器中

Ios 将图像与文本一起保存在web服务器中,ios,objective-c,Ios,Objective C,我需要在web服务器上发布图像和文本。文本数据保存,但图像不保存。然后我尝试了下面的代码。现在文本数据也不保存 NSData *imageData = UIImagePNGRepresentation(chosenImage); NSString *requestString =[NSString stringWithFormat:@"UserId=%@&CategoryId=%@&Continent=%@&Country=%@&City=%@&Gend

我需要在web服务器上发布图像和文本。文本数据保存,但图像不保存。然后我尝试了下面的代码。现在文本数据也不保存

NSData *imageData = UIImagePNGRepresentation(chosenImage);

NSString *requestString =[NSString stringWithFormat:@"UserId=%@&CategoryId=%@&Continent=%@&Country=%@&City=%@&Gender=%@&ImageName=%@&ImageData=%@&AgeRange=%@",UserId,CategoryId,continentTextfield.text,countrytextfield.text,citytextfield.text,gender,imagename,imageData,ageTextfield.text];



NSString *url=[NSString stringWithFormat:@"http://192.168.2.4:98/UserImage.svc/InsertFacialImage?%@",requestString];

//----------------------





NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;

[request setURL:[NSURL URLWithString:url]];

[request setHTTPMethod:@"POST"];

// Create 'POST' MutableRequest with Data and Other Image Attachment.

NSString *boundary = @"---------------------------14737809831466499882746641449";

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];

[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *postbody = [NSMutableData data];

//image

[postbody appendData:[NSString stringWithFormat:@"\r\n--%@\r\n",boundary]];

[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; file=\"image\"; filename=\"%@.png\"\r\n", imageData]dataUsingEncoding:NSUTF8StringEncoding]];

[postbody appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];

[postbody appendData:[NSData dataWithData:imageData]];



[request setHTTPBody:postbody];
//-----------------------

NSURLConnection *connReq = [NSURLConnection connectionWithRequest:request delegate:self];



if (connReq) {



    NSLog(@"Connection Sucessful");
receivedData=[[NSMutableData alloc]init]

}

else {

    NSLog(@"failed");

}

[connReq start];

您是否从服务器收到任何错误?您确定这不是服务器没有正确解析POST数据的问题吗?服务器工作正常。安卓开发者成功发布图片