【发布时间】:2014-03-27 06:28:38
【问题描述】:
我正在使用 NSURLConnection 来集成 Web 服务。
我的代码如下:
NSURL *url = [NSURL URLWithString:Sign_Up_URL];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
NSString *params = [NSString stringWithFormat:@"vimage=%@&@"vFname=%@&vLname=%@&vEmail=%@&vPassword=%@&vDeviceType=%@&vDeviceToken=%@",image_data,txt_first.text,txt_last.text,txt_email.text,txt_password.text,@"IOS",@"safasf423526dgdsgdsg"];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:header_filed forHTTPHeaderField:@"X_API_KEY"];
[urlRequest setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
[NSURLConnection sendAsynchronousRequest:urlRequest
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *connectionError) {
// handle response
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSDictionary *json_response = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"%@",json_response);
// [self login_response:json_response];
}];
但是如何使用此参数上传图片?
帮助。
【问题讨论】:
-
您必须在 NSData 中转换您的图像,然后您必须使用您的参数上传该数据。
-
@NiravPatel,感谢您的回复!我已经尝试过转换 NSdata 但没有得到成功的结果。
-
解决方案请参考stackoverflow.com/questions/11084403/…。可能有用..
-
您是否收到任何错误或响应?
-
您是否尝试过使用 ASIHTTPRequest 来发布带有其他参数的图像数据?..@user2893370
标签: ios iphone objective-c nsurlconnection nsurlrequest