1

I have a string: <api address>/<parameters>?fmt=json
When I create an NSURL object from the string, the URL is: <api address>/<parameters>%3Ffmt=json

When I send the request with this URL (using an NSURLSession), however, it gets denied access, as the API wants the ? and doesn't accept %3F. How do I decode the URL to have the ? return so the API will accept the request?

UPDATE

NSURL construction

let urlRequestString = "<api url>?fmt=json&api_key=" + <key> let apiRequestURL = NSURL(fileURLWithPath: urlRequestString)

Karl Thompson
  • 65
  • 1
  • 7

1 Answers1

0

You're using the wrong initializer, which is causing bogus results. NSURL(fileURLWithPath: urlRequestString) is intended for creating file:// URLs. It translates your URL into a format suitable for the filesystem. It's designed for file use only, so you shouldn't use it here.

If you change the initializer to be NSURL(string: urlRequestString) then your URL should be OK.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170