iphone download image with variable using ASIHTTPR

2020-07-27 02:14发布

I got stuck something annoying.

I uploaded images to server it's ok. However, when i try to download image from server i want to get image with string variable. here is my php code server side

         ....

        echo "image_getting;";
        $fullPath = $_POST['download_image'];
        echo file_get_contents($fullPath);

         ....

if i remove first line from my server [request responseData] working correctly. However, i want to also get "image_getting;" because i am also downloading some different types.

if i can clear, iphone side when i say

- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSString *responseString = [request responseString];
    NSLog(@"%@",responseString);

    NSArray *resultResponseArray = [responseString componentsSeparatedByString:@";"];
    if([[resultResponseArray objectAtIndex:0] isEqualToString:@"image_getting"])
    {
          NSData *responseData = [request responseData];
          UIImage * image = [UIImage imageWithData:aData];
          .......
    }
    else if...
....
}

as you can see above response data also taking echo "image_getting" how do i split it. I tried to convert and split them it didn't work.

I should say, i am very bad with php.

I will be appreciated, if someone help me. Thanks

EDIT:Solution Php side

    header('X-Return: image_getting;');
    $fullPath = $_POST['download_image'];
    echo file_get_contents($fullPath);

iphone side

    NSLog(@"header %@",[[request responseHeaders] objectForKey:@"X-Return"]);

1条回答
劫难
2楼-- · 2020-07-27 02:29

Why don't you put the "image_getting" into a HTTP header in the response instead? That would make the parsing much easier - you can then retrieve the header:

NSString *whatever = [[request responseHeaders] objectForKey:@"X-Whatever"];

and then [request responseData] will only contain the image.

查看更多
登录 后发表回答