0

I have a api which needs to use a url string in order to work (wouldn't work with the normal NSDictionary request). The string I'm trying to use is

http://10.1.10.25:8181/config?param={"obj":["hours"]}

However, the following code which I used to escape the characters does not work. It returns a bad url error. What is the proper way to escape characters here?

NSURL *url = [NSURL URLWithString:@"http://10.1.10.25:8181/config?param={\"obj\":[\"hours\"]}"];
// Error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x8ca3780 {NSUnderlyingError=0x8ca6980 "bad URL", NSLocalizedDescription=bad URL}

Below is a picture of a working example using a online REST service. this works

Yan Yi
  • 763
  • 1
  • 10
  • 29
  • You need to encode the URL: http://stackoverflow.com/a/3426140/1445366 You may want to make your own AFNetworking request serializer so that you don't need to duplicate this logic outside of your networking stack. – Aaron Brager Jun 04 '14 at 17:52

1 Answers1

1

In this case you just need to encode your param like this: http://10.1.10.25:8181/config?param=%7B%22obj%22%3A%5B%22hours%22%5D%7D

Calle Bergström
  • 480
  • 4
  • 12