我从另一个视图获取PassedUserId值。我可以在日志中打印该值。但它没有分配给url字符串。在这里,我试图传递文本与图像。
NSString *requestString =[NSString stringWithFormat:@"UserId=%@&CategoryId=%@&Continent=%@&Country=%@&City=%@&Gender=%@&ImageName=%@&AgeRange=%@",PassedUserId,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 = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage, 0.2f);
[request addValue:@"image/JPEG" forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:data]];
[request setHTTPBody:body];
NSData *returnData;
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"Ret: %@",returnString);
答案 0 :(得分:0)
我注意到的第一件事是你交换了两个值:
stringWithFormat:@"UserId=%@&CategoryId=%@...",CategoryId,PassedUserId
您能更具体地了解CategoryId
和PassedUserId
的数据类型吗?
如果他们是字符串,那么你就是正确行事。如果它们是数据类型整数,则应使用%i
而不是%@
。