2010-10-12 67 views
0

我試圖在iPhone上調用Web服務,如下所示;如何在NSURL中使用反斜槓

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

當此行被執行網址爲。但是當我從上面的調用中刪除「\」時,url包含該值。

我已經嘗試使用「\\」,但它沒有奏效。這裏是我的代碼

NSString *Domain = [NSString stringWithFormat:@"DOMAIN"]; 
NSString *name = [NSString stringWithFormat:@"UserName"]; 
NSString *urlString = [NSString stringWithFormat:@"http://%@\\%@:[email protected]",Domain,name]; 

//Above lines executes properly and contains the following 
"https://DOMAIN\UserName:[email protected]" 

但是,當下面一行被執行網址是零

NSURL *url = [NSURL URLWithString:urlString]; 

任何機構可以幫助我如何我可以把「\」的網址是什麼?

謝謝。 亞薩爾

回答

3

換個\在它面前逃脫它:

http://DOMAIN\\Username 
+0

就這麼簡單。反斜槓用作許多語言的特殊輸入字符,例如'\ n'表示換行。 – Emil 2010-10-12 15:10:24

+0

我已經試過這個。而URL變成零。請建議 – Yasar 2010-10-18 13:15:32

0

使用的UTF8編碼的字符串。

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