+[NSURL URLWithString:] returning nil

ios, iphone, nsurl, uiimageview

Solution

for some weird reason I have to use : `[NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];`

when I create the `URL` and this solved the issue.

Problem

I use this code to load a `UIImage` from a `URL`: ``` NSURL *imageURL = [NSURL URLWithString:@"http://testwebsite.com/image.png"]; NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL]; imageView.image = [UIImage imageWithData: imageData]; ``` but I'm stuck at a `URL` that looks like this one : `http://www.testwebsite.com/getFile?userID=123` this works fine in the browser but returns nil in the `imageData` variable above. how can I load the image from such an obscured `URL` (i.e. from a `URL` that does not show off the file name but rather redirects to the image file) ? thank you in advance.

Original source