【发布时间】:2014-06-13 12:56:33
【问题描述】:
我从另一个 ViewController 获得了一个值。我可以在日志中打印它,但这里的问题是我得到了这种格式的值
(
201 )
我从 JSON 数据中得到这个值。我无法获取 UITextField 中的值。同时它不适用于 urlstring,即我在下面的代码中提到了请求的字符串。
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);
我需要与该字符串一起运行 NSUrlRequest。
【问题讨论】:
标签: ios objective-c ios7 nsstring nsurlrequest