iphone下载图像与变量使用ASIHTTPRequest [英] iphone download image with variable using ASIHTTPRequest

查看:92
本文介绍了iphone下载图像与变量使用ASIHTTPRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入困境。



我将图像上传到服务器,没关系。
但是,当我尝试从服务器下载图像时,我想使用字符串变量获取图像。这里是我的php代码服务器端

  .... 

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

....

如果我从我的服务器删除第一行[请求responseData]正常工作。
但是,我也想得到image_getting;因为我也在下载一些不同的类型。



如果我可以清除,iphone侧
当我说



$($)$($)$($)$($)$($)$($)$
NSLog(@%@,responseString);

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

正如你可以看到上面的回复数据也采取回声image_getting我如何拆分它。
我试图转换并拆分它们不起作用。



我应该说,我对php非常糟糕。



如果有人帮我,我将不胜感激。
感谢



编辑:解决方案Php端

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

iphone侧

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


解决方案

为什么不把image_getting响应中的HTTP头?这将使解析更容易 - 您可以检索标题:

  NSString * whatever = [[request responseHeaders] objectForKey: @ X-不管]; 

然后[request responseData]将只包含图像。


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"]);

解决方案

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.

这篇关于iphone下载图像与变量使用ASIHTTPRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆