开发者

How to use back slash in NSURL

开发者 https://www.devze.com 2023-01-19 12:49 出处:网络
I am trying to call a web service on iPhone as follows; NSURL *url = [NSURL URLWithString:@\"http://DOMAIN\\Username:Password@IPAddress/ServiceName\"];

I am trying to call a web service on iPhone as follows;

NSURL *url = [NSURL URLWithString:@"http://DOMAIN\Username:Password@IPAddress/ServiceName"];    

When this line is executed url is nil. But when i remove "\" from above call, url contains the value.

I have already tried using "\\" but it didn't worked. Here is my code

NSString *Domain = [NSString stringWithFormat:@"DOMAIN"]; 
NSString *name = [NSString stringWithFormat:@"UserName"]; 
NSString *urlS开发者_开发技巧tring = [NSString stringWithFormat:@"http://%@\\%@:password@IPAddress",Domain,name]; 

//Above lines executes properly and contains the following 
"https://DOMAIN\UserName:password@IPAddress" 

But when the following line gets executed url is nil

NSURL *url = [NSURL URLWithString:urlString];

Can any body help me how i can put "\" in URL?

Thanks. Yasar


Put another \ in front of it to escape it:

http://DOMAIN\\Username


Use an UTF8 encoding for the String.

NSURL * url = [NSURL URLWithString:[stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
0

精彩评论

暂无评论...
验证码 换一张
取 消