nsurlerrordomain - NSURL Bad URL error when using stringByAddingPercentEscapesUsingEncoding -
i concatenated 2 strings url, below method concatenating strings: purpose of go url namely:
https://vula.uct.ac.za/portal/pda/9f563cb2-24f9-481f-ab2e-631e85c9f3aa/tool-reset/10f71bdb-24b9-4060-bf6d-2c9654253aa3
to shorter url displays part of webpage , is:
https://vula.uct.ac.za/portal/tool-reset/10f71bdb-24b9-4060-bf6d-2c9654253aa3
-(nsstring *)cropurl:(nsstring *)inputurl{ nsstring *outputurl ; nsrange match; match = [inputurl rangeofstring: @"tool-reset"]; //gives index , range of string "tool-reset" int toollen = match.location+match.length ; //gives index after "tool-reset" nsstring*tempidentifier = [inputurl substringfromindex:toollen] ; //gets characters after "tool-reset" nsstring *firsturl = @"https://vula.uct.ac.za/portal/tool-reset" ; //first part of url nsmutablearray *concaturl = [[nsmutablearray alloc] initwithcapacity:2] ; // array concat firsturl , tempidentifier [concaturl addobject:(nsstring *)firsturl] ; [concaturl addobject:(nsstring *) tempidentifier] ; outputurl = [concaturl componentsjoinedbystring:@""] ; //concatenatd outputurl outputurl = [outputurl stringbyaddingpercentescapesusingencoding:nsutf8stringencoding] ; //encoding return outputurl ;
}
*note website requires user log in, done earlier , these methods called once login successful.
i sent concatenated url connection method , error below:
error domain=nsurlerrordomain code=-1000 "bad url" userinfo=0x1d51f7d0 {nsunderlyingerror=0x1e547980 "bad url", nslocalizeddescription=bad url}
the unconcatenated url doesn't have problem though.
the url in question is:
https://vula.uct.ac.za/portal/tool-reset/10f71bdb-24b9-4060-bf6d-2c9654253aa3
the url correct , has been tested. (again, note site requires log in)
i did use:
stringbyaddingpercentescapesusingencoding:nsutf8stringencoding
before sending the connection, still same error.
all other links work, links don't work ones concatenated. these concatenated strings work in normal web browser.
any ideas wrong?
one way achieve then:
nsurl *input = [nsurl urlwithstring:@"https://vula.uct.ac.za/portal/pda/9f563cb2-24f9-481f-ab2e-631e85c9f3aa/tool-reset/10f71bdb-24b9-4060-bf6d-2c9654253aa3"]; nsstring *identifier = input.lastpathcomponent; nsurl *base = [nsurl urlwithstring:@"https://vula.uct.ac.za/portal/tool-reset/"]; nsurl *output = [base urlbyappendingpathcomponent:identifier];
Comments
Post a Comment