Ios 使用HTTP Post将图像发布到web服务器

Ios 使用HTTP Post将图像发布到web服务器,ios,objective-c,ios7,Ios,Objective C,Ios7,我正在使用下面的代码成功地将图像发布到web服务器。但这里的问题是,只需单击按钮操作,图像就会保存3次 NSString *requestString =[NSString stringWithFormat:@"UserId=%@&CategoryId=%@&Continent=%@&Country=%@&City=%@&Gender=%@&ImageName=%@&AgeRange=%@",UserId,CategoryId,contin

我正在使用下面的代码成功地将图像发布到web服务器。但这里的问题是,只需单击按钮操作,图像就会保存3次

NSString *requestString =[NSString stringWithFormat:@"UserId=%@&CategoryId=%@&Continent=%@&Country=%@&City=%@&Gender=%@&ImageName=%@&AgeRange=%@",UserId,CategoryId,continentTextfield.text,countrytextfield.text,citytextfield.text,gender,imagename,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 = @"0x0hHai1CanHazB0undar135";
 NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];

NSData *data = [NSData dataWithData:UIImagePNGRepresentation(chosenImage)];
[request addValue:@"image/png" forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:data]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(@"Ret: %@",returnString);

//NSURL Connection request 


NSURLConnection *connReq = [NSURLConnection connectionWithRequest:request delegate:self];
 if (connReq) {

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

}

else {

    NSLog(@"failed");

}

[connReq start];

你的问题是什么?不是一次保存三次图像。意味着如果上传一张图片,我会在数据库中得到3份副本