开发者

Inserting special char un NSString for URL use

开发者 https://www.devze.com 2023-01-03 11:07 出处:网络
I\'m using HTTP connection to share data with my JSON server. I use URLs like \"MyServlet?param1=value1\" and so on...

I'm using HTTP connection to share data with my JSON server.

I use URLs like "MyServlet?param1=value1" and so on...

I'm now facing a problem with one of my servlet (I can't change it because some other views are using it) :

The servlet is working with a syntax including those symbols "{" and "}".

The exact syntax is

{(value1_value2)(value3_value4)(value5_value6)}{(value7_value8)(value9_value10)(value11_value12)}{(value13_value14)(value15_value16)(开发者_Go百科value17_value18)}

Values are integers, the problem is only when I use "{" and "}" my UrlConnection returns an error for bad URL.

I use this to instantiate my NSString :

NSString *myURL = [NSString stringWithFormat:@"http://somesite.com/Servlet?PARAM={(%@)}"];

How can I code those char in my NSString ?

Thanks in advance !


You need to URL encode those characters. Replace { with %%7b and } with %%7d in your string format. (The extra % is needed because % is special in format strings)

0

精彩评论

暂无评论...
验证码 换一张
取 消