使用多个图像的IOS Post请求

使用多个图像的IOS Post请求,ios,post,base64,nsurlconnection,nsmutableurlrequest,Ios,Post,Base64,Nsurlconnection,Nsmutableurlrequest,下面是我向我的服务器发送包含4个Base64图像数据的post请求的代码 NSString *postURL = [NSString stringWithFormat:@"name=%@&mobile=%@&email=%@&bday=%@&image=%@&img1=%@&img2=%@&img3=%@",@"abin",@123",@"abc@gmail.com",@"01-01-1990",[base64Value]image,[ba

下面是我向我的服务器发送包含4个Base64图像数据的post请求的代码

NSString *postURL = [NSString stringWithFormat:@"name=%@&mobile=%@&email=%@&bday=%@&image=%@&img1=%@&img2=%@&img3=%@",@"abin",@123",@"abc@gmail.com",@"01-01-1990",[base64Value]image,[base64 value] of img1,[base64 value] of img2,[base64 value] of img3"];

NSData *postData = [postURL dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:[NSURL URLWithString:@"MY_URL"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
这里所有图像值img1、image、image都是base64值。

将此请求发送到服务器时,10次中有6次失败

通过Wi-Fi的成功率很高,通过移动数据的成功率很低

图像转换使用以下代码完成:

- (NSString *)encodeToBase64String:(UIImage *)image {
NSData *data = UIImageJPEGRepresentation(image, 1.0);
NSData *imageBase64Data = [data base64EncodedDataWithOptions:0];
NSString *imageBase64String = [[NSString alloc] initWithData:imageBase64Data encoding: NSUTF8StringEncoding];
return imageBase64String;
}
任何一次,请帮助我了解如何使用POST请求成功地将多个图像发送到服务器,即使网络连接很慢。(2G)

在界面中:-

dispatch_queue_t queue;
在viewdidload中:

 if (!queue) {
        queue = dispatch_queue_create("name", DISPATCH_QUEUE_CONCURRENT);
    }
在您的方法中:

dispatch_async(queue, ^{

            //do the post code here
        });
        dispatch_async(dispatch_get_main_queue(), ^{

           //do the ui update part here
        });

   }

凯达:谢谢你的回复。但对我来说,我的代码是有效的,但并不总是有效的。我也不想使用响应更新任何UI。