2012-10-18 52 views
0

需要幫助,從文本框的條目替換我的空間張貼到GET的XCode的iOS替代空間與+

我當前的代碼:

NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text]; 
NSURL *add = [NSURL URLWithString:urlString]; 

[messageView loadRequest:[NSURLRequest requestWithURL:add]]; 

不過我試過

NSString *finalAdd = [add stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 
+0

[URL解碼/編碼的NSString]的可能重複(http://stackoverflow.com/questions/6688287/url-decoding-encoding-nsstring) –

回答

0

檢查出this postthis SO question。兩者都爲編碼url提供了很好的解決方案。

+0

請只網址或鏈接的答案是真正的好消息,並將很快被社區拒絕:) –

1

你應該逃脫參數

NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", [messageBox.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSURL *add = [NSURL URLWithString:urlString]; 
+1

給我:'NSURL'沒有明顯的@interface聲明選擇器'stringByAddingPercentEscapesUsingEncoding:' –