-2

Using URLComponents, is there a way to avoid percent encoding of host?

var components = URLComponents()
components.scheme = "https"
components.host = "endpoint.com/v1/api.php?"
// ends up as https://endpoint.com%2Fv1%2Fapi.php%3F? but I want it to stay as https://endpoint.com/v1/api.php?

This question is about avoiding encoding, not adding encoding as the question linked as duplicate states.

Cindy Meister
  • 23,572
  • 20
  • 33
  • 43
nambatee
  • 1,268
  • 12
  • 23

1 Answers1

3

"/v1/api.php" is not part of the host, but rather the path.

Use this:

var components = URLComponents()
components.scheme = "https"
components.host = "endpoint.com"
components.path = "/v1/api.php"
Gereon
  • 14,827
  • 4
  • 36
  • 62