Search code examples
iphoneobjective-cxcodepostasihttprequest

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;
}

Solution

  • 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.