Search code examples
swiftnsurlnsurlrequest

Swift - Using less than "<" operator in REST api search with NSURLRequest


I am new to this HTTP request stuff so I apologize if my terminology is not correct.

What I am trying to do is search a database using a particular query string. I have used it successfully using curl and partially successfully using NSURLRequest when I don't use the "<" operator. Here's the string:

https://"company"/api/v2/search.json?query=type:ticket%20status<solved

Like I said, it works using curl but when trying to build it into an app using NSURLRequest it fails, returning a -1002 bad url error. If I change the last part to status:solved just to test, it'll work fine also.

What can I do to allow use of the less than "<" operator within NSURLRequest? Thanks


Solution

  • Try encoding that part of your URL.

    let urlString = https://"company/api/v2/search.json?query=type:ticket%20"
    let queryString = "status<solved".stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
    let fullUrl = urlString + queryString