-1

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
  • 25,071
  • 21
  • 34
  • 43
nambatee
  • 1,478
  • 16
  • 27

1 Answers1

5

"/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
  • 17,258
  • 4
  • 42
  • 73