ASIHttpRequest POST images
I am using ASIHttpRequest to POST user and pass to url that executes php code. This code returns a url string but now, also images are required in order to show it after on a tableview. How to save images from that url on iphone using ASIHttpRequest?
- (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;
}
If you want to store the image into user phone that time u may use to HJcache API which use to store the client side store the images and that to use.
If you want to save images you have to make a download request directly to your image. At this moment you are getting a HTTP page as a response (saving this).
So basically:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:<URL WITH YOUR IMAGE>];
[request setDownloadDestinationPath:@"/image.jpg"];
Alternatively, your response could contain an encoded image (say, 64-bit encoded) that you can parse out of the response.
精彩评论