I am trying to compose a representative URLComponents()
in the app I am designing.
Here is the code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var components = URLComponents()
components.scheme = "http"
components.host = "0.0.0.0"
components.port = 9090
let queryItemToken = URLQueryItem(name: "/predict?text", value: "what's your name?")
components.queryItems = [queryItemToken]
print(components.url as Any)
}
}
Here is the output of the above snippet:
Optional(http://0.0.0.0:9090?/predict?text=what's%20your%20name?)
The above output doesn't work on the server because of the ? between the port and the query!
How can I prevent URLComponents()
from inserting this redundant ? between the port and the query!
The target output: Optional(http://0.0.0.0:9090/predict?text=what's%20your%20name?)