-->

Strange Issue with NSURL with Xocode6.1

2019-09-20 14:33发布

问题:

I have a strange issue with Xcode6.1

_mainURl is my ' ServerLink '

service is ' GetUserById '

NSString* str = [NSString stringWithFormat:@"%@%@",_mainURl,service];
NSURL *url = [NSURL URLWithString:str];

When I append two strings and Create a url with NSURL, url getting 'null'

But, When I directly given the server link followed by serviceName I can generate URL.

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"ServerLink/GetUserById"]];

回答1:

Based on what you have written, the string you format would be "ServerLinkGetUserById". That is different to the string you enter manually of @"ServerLink/GetUserById".

Try updating your format to be:

NSString* str = [NSString stringWithFormat:@"%@/%@",_mainURl,service];


回答2:

NSString* str = [NSString stringWithFormat:@"%@/%@",_mainURl,service];
NSURL *url = [NSURL URLWithString:str];

don't you try like this ??

i think i am not sure exact what issue having you but as your bellow description, i think you left this part