【问题标题】:ASIHttpRequest POST imagesASIHttpRequest POST 图片
【发布时间】:2011-12-03 23:08:31
【问题描述】:

我正在使用 ASIHttpRequest POST 用户并传递给执行 php 代码的 url。此代码返回一个 url 字符串,但现在,还需要图像才能在 tableview 上显示它。如何使用 ASIHttpRequest 在 iphone 上保存来自该 url 的图像?

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

【问题讨论】:

    标签: iphone objective-c xcode post asihttprequest


    【解决方案1】:

    如果您想将图像存储到用户手机中,您可以使用 HJcache API,该 API 用于存储客户端存储图像和使用的图像。

    【讨论】:

      【解决方案2】:

      或者,您的响应可以包含一个编码图像(例如,64 位编码),您可以从响应中解析出来。

      【讨论】:

        【解决方案3】:

        如果您想保存图片,您必须直接向您的图片发出下载请求。此时,您将收到一个 HTTP 页面作为响应(保存)。

        所以基本上:

        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:<URL WITH YOUR IMAGE>];
        [request setDownloadDestinationPath:@"/image.jpg"];
        

        【讨论】:

          猜你喜欢
          • 2011-12-19
          • 2011-09-08
          • 1970-01-01
          • 1970-01-01
          • 2011-07-06
          • 2011-07-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多