2011-10-09 85 views
0

我正在使用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; 
} 

回答

0

如果您想將圖像存儲到用戶手機中,那麼您可以使用HJcache API來存儲客戶端存儲的圖像和使用的圖像。

0

如果你想保存圖像,你必須直接向你的圖像下載請求。此時你正在獲得一個HTTP頁面作爲響應(保存這個)。

所以基本上:

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

或者,你的反應可以包含一個編碼的圖像(比如,64位編碼),您可以解析出響應。