Bu işlemde, Çoklu form verileri yapmaya çalışıyorum.Ancak verilerim uygun olmadığından bir iç hata aldım.iOS: Çok satırlı veri biçimi hatası
"Content-Disposition: form-data; = "Veri" adını verilere benim parametre ben do.Here nasıl bilmiyorum benim kod
NSString *stringUrl [email protected]"http://URL";
// NSString *mimetype = @"image/jpeg";
UIImage *img =[UIImage imageNamed:@"1418954654.png"];
NSData *imageDataa = UIImagePNGRepresentation(img);
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"name",@"first_name",@"name2",@"last_name",@"10-03-2356",@"dob",@"[email protected]",@"email",@"12452",@"facebook_id",@"M",@"gender",@"123456",@"password",@"12345689",@"phone_no",@"U",@"user_type", nil];
//
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:stringUrl]];
// NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setHTTPShouldHandleCookies:NO];
[request setTimeoutInterval:60];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"unique-consistent-string";
// set Content-Type in HTTP header
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@ ;", boundary];
[request setValue:contentType forHTTPHeaderField: @"Content-Type"];
// post body
NSMutableData *body = [NSMutableData data];
[parameters enumerateKeysAndObjectsUsingBlock:^(NSString *parameterKey, NSString *parameterValue, BOOL *stop) {
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n,", parameterKey] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@\r\n", parameterValue] dataUsingEncoding:NSUTF8StringEncoding]];
}];
if (imageDataa) {
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=%@; filename=imageName.jpg\r\n", @"photo"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:imageDataa];
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
// NSLog(@"bodu%@",body);
}
[body appendData:[[NSString stringWithFormat:@"--%@d--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// NSLog(@"bodu%@",body);
// setting the body of the post to the reqeust
[request setHTTPBody:body];
// set the content-length
NSString *postLength = [NSString stringWithFormat:@"%d", [body length]];
NSLog(@"bodyy%@",postLength);
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if(data.length > 0)
{
//success
NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"==%@",newStr);
}
else
{
NSLog(@"==%@",error.localizedDescription);
}
}];