0

In my app I am passing a string to service which sets some data to remote database. Everything works perfect as far as I don't have "&" in my string.

I am using this to pass the parameters:

NSString *urlString = [[NSString
 stringWithFormat:@"http://someservice.com/some/some_setstatus.php?status=active&name=%@",
 merchant] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

My guess is when it's checking the name with the name saved in the database, it's not able to find one because of '&'.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ashutosh
  • 5,614
  • 13
  • 52
  • 84
  • See http://stackoverflow.com/questions/705448/iphone-sdk-issue-with-ampersand-in-the-url-string – Joe Apr 19 '13 at 18:35
  • That's not clear enough and when implemented in my case doesn't solve the problem. – Ashutosh Apr 19 '13 at 18:50
  • See this answer: http://stackoverflow.com/a/1192589/1226963 You need to create that category method then call that method on just your `merchant` variable. – rmaddy Apr 19 '13 at 19:37

3 Answers3

0

You are unable to pass "&", as it will be treated as a delimiter for URL parameters. "&" is a reserved character and you can consider encoding "&" as a combination of allowed characters. Take a look at RFC 3986 and the answer to this question.

Community
  • 1
  • 1
Arun
  • 791
  • 6
  • 10
0

You need to escape the & character for url (more info: http://www.ietf.org/rfc/rfc3986.txt)
Have a look at https://github.com/tagyro/GTM/blob/master/Foundation/GTMNSString%2BURLArguments.h
This is a clone of Google Toolbox for Mac from their SVN.

tagyro
  • 1,638
  • 2
  • 21
  • 36
-1

I believe you need to urlEncode to the string which will properly encode any special characters. See http://www.w3schools.com/tags/ref_urlencode.asp for more information.

Regards,

Steve