开发者

ASIHttpRequest POST images

开发者 https://www.devze.com 2023-04-12 06:36 出处:网络
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 im

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号