开发者

Problem in downloading image from server in iPhone

开发者 https://www.devze.com 2022-12-20 05:31 出处:网络
I have an Image named \"John and Tony.png\".When I tried to download the image from my code wi开发者_运维问答th this name via an http request no image is shown.But if I remove the space between the wo

I have an Image named "John and Tony.png".When I tried to download the image from my code wi开发者_运维问答th this name via an http request no image is shown.But if I remove the space between the words like "JohnandTony.png" then there is no problem to download the image.But I can't want to remove the spaces.Is there any way to do that?

Thanx


you need to escape the spaces with "%20"s.

NSString *imageStr = @"http://whatever.com/John and Tony.png";
NSString *imageStrEscaped = [urlStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

Then use this string as the url.


I think you are creating the imagestring the wrong way. Try the following:

NSString *imagestring = @"28.162.10.2/images/John and Tony.png";  
imagestring = [imagestring stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];


Your URL doesn't must contain spaces. If you want let this name, you must use the %20 to replace the spaces like that:

"John%20and%20Tony.png"

0

精彩评论

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

关注公众号