0

I have a string which ends with percent sign(%),

this string is prepared for an URL request as a parameter:

NSString *parameter = @"/param=%";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL urlWithString:[NSString stringWithFormat:@"http://www.whatev%@",parameter]]];

The request returns nil.

I've tried:

NSString *parameter = @"/param=\uFF05";
//request returns nil

and

NSString *parameter =  @"/param=%";
NSString *newParameter = [parameter stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//request returns /param=%25 ...where does 25 come from?!

How could I have only one % converted to a request url?

Any advice would be appreciated.

bluenowhere
  • 2,683
  • 5
  • 24
  • 37

2 Answers2

0

The percent sign has a special purpose in URL's and is used to encode special characters of all kinds. For example a space ( ) is %20 and the percent sign itself is %25.

http://en.wikipedia.org/wiki/Percent-encoding

The last one should be correct, I assume you have problems using it as a request?

Covalence
  • 130
  • 7
0

escape sequence for % is %%, so @"/param=%%" should solve the problem

thorb65
  • 2,696
  • 2
  • 27
  • 37