I am developing an application in which I need to encode URL. I tried using http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/ and
[NSString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]
but its not working out for me. Is there any alternate URL encoder class for iphone like java?
How to achieve it?? Thanks in advance...
Asked
Active
Viewed 3,792 times
1
-
try NSUTF8StringEncoding if it works. But if you want encoding for removing space in URL than the method you are using is fine – Javal Nanda Dec 07 '10 at 08:29
-
@Javal Nanda I tried NSUTF8StringEncoding also it does not work.It dont encode certain special characters(like ";:) – roger Dec 07 '10 at 08:57
-
@BoltClock thats what I wrote above.. NSUTF8StringEncoding dont encode some special characters(All the special characters needs to be encoded in my app).So whats the alternate way to match java's URL encoder class? – roger Dec 07 '10 at 09:48
3 Answers
3
Try the following for URL encoding :
NSString *url= [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)originalpath, NULL, CFSTR(";:"), kCFStringEncodingUTF8) autorelease];

Hemang
- 26,840
- 19
- 119
- 186

Najeebullah Shah
- 4,164
- 4
- 35
- 49
0
You can try the following for URL encoding:
`NSString *urlString = [NSString stringWithFormat:@"http://www.abc.com/parsexml.aspx?query=%@", [searchBar.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];`

Robert
- 5,278
- 43
- 65
- 115

Chris Alan
- 1,426
- 14
- 14