1

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...

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
roger
  • 11
  • 1
  • 2
  • 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 Answers3

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
0

You can refer to this post to find your solution.

Community
  • 1
  • 1
raaz
  • 12,410
  • 22
  • 64
  • 81