StringWithContentsOfURL does not work with a specific string

I have code similar to the following with this url ... If I use the first * url, the web page will return null. If I put this URL in a URL shortening system like bit.ly, it will work and return the HTML pages as a string. Can I only think that I have invalid characters in my first * url? Any ideas?

NSString *url =@"http://www.testurl.com/testing/testapp.aspx/app.detail/params.frames.y.tpl.uk.item.1.cm_scid.TB-test/left.html.|metadrill,html/walk.yah.ukHB?cm_re=LN-_-OnNow-_-TestOne";

//above *url does not work, one below does
NSURL *url =[NSURL URLWithString: @"http://bit.ly/shortened"];
NSString *webpage = [NSString stringWithContentsOfURL:url];
+3
source share
1 answer

You probably need to avoid some characters in the first URL, as shown below:

NSString *url =@"http://www.testurl.com/testing/testapp.aspx/app.detail/params.frames.y.tpl.uk.item.1.cm_scid.TB-test/left.html.|metadrill,html/walk.yah.ukHB?cm_re=LN-_-OnNow-_-TestOne";
NSString *escapedURL = [url stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString *webpage = [NSString stringWithContentsOfURL:[NSURL URLWithString:escapedURL]];

URL- , URL- , ( URL-, , (|), ).

+3

Source: https://habr.com/ru/post/1711235/


All Articles