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
  • 665,005
  • 155
  • 1,345
  • 1,328
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,372
  • 18
  • 120
  • 180
Najeebullah Shah
  • 4,154
  • 3
  • 34
  • 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,231
  • 43
  • 62
  • 114
Chris Alan
  • 1,406
  • 14
  • 14
0

You can refer to this post to find your solution.

Community
  • 1
  • 1
raaz
  • 12,160
  • 21
  • 61
  • 81