Search code examples
objective-cnsstringnsurlrequest

objective C NSString stringwithformat of a URL


i need my application to send an HTTP request to my server, this is the link, but for some reason, when i create an NSString stringwithformat not all of the string is copied into the string,

this is my URL:

http://192.168.50.204:8080/webapi/originate?sofia/internal/408%25192.168.50.204%20'set:effective_caller_id_number=722772408,bridge:sofia/gateway/012smile/<PHONENUMBER>@212.199.220.21'%20inline%200545890183%200545890183

if i put it in my browser it is working fine.

and this is the code:

self.feedURLString = [NSString stringWithFormat:@"http://192.168.50.204:8080/webapi/originate?sofia/internal/%@%25192.168.50.204%20'set:effective_caller_id_number=722772%@,bridge:sofia/gateway/012smile/%@@212.199.220.21'%20inline%20%@%20%@",extention,extention,PhoneNumber,PhoneNumber, PhoneNumber];

keep in mind that there are some %20 and %25 in the URL, maybe it causes the problem...

the string i get in the NSLog is:

feedURLString = http://192.168.50.204:8080/webapi/originate?sofia/internal/408220'set:effective_caller_id_number=722772408,bridge:sofia/gateway/012smile/0545890183@212.199.220.21' 93610576nline2@2@


Solution

  • remove the %20 and %25 from the string then use the stringByAddingPercentEscapesUsingEncoding command from NSString

    string = [sURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];