Problem in downloading image from server in iPhone
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"
精彩评论