ASIHttpRequest POST图像
问题描述:
我正在使用ASIHttpRequest POST用户并传递给执行php代码的url。此代码返回一个url字符串,但现在,还需要图像才能在tableview中显示它。如何使用ASIHttpRequest从iPhone上的URL保存图像?ASIHttpRequest POST图像
- (void)getData
{
activityIndicator.hidden = NO;
[activityIndicator startAnimating];
NSURL *url = [NSURL URLWithString:@"http://test.com/iphone.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSLog(@"URL = %@",url);
[request setValidatesSecureCertificate:NO];
[request setRequestMethod:@"POST"];
[request setPostValue:@"user1" forKey:@"user"];
[request setPostValue:@"admin" forKey:@"pass"];
[request setDelegate:self];
[request startAsynchronous];
NSString *response = [NSString stringWithContentsOfFile:
[request downloadDestinationPath] encoding:[request responseEncoding] error:nil];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]);
[activityIndicator stopAnimating];
activityIndicator.hidden = YES;
}
答
如果您想将图像存储到用户手机中,那么您可以使用HJcache API来存储客户端存储的图像和使用的图像。
答
如果你想保存图像,你必须直接向你的图像下载请求。此时你正在获得一个HTTP页面作为响应(保存这个)。
所以基本上:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:<URL WITH YOUR IMAGE>];
[request setDownloadDestinationPath:@"/image.jpg"];
答
或者,你的反应可以包含一个编码的图像(比如,64位编码),您可以解析出响应。