-1

使用URLComponents,有没有办法避免主机的百分比编码?

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?

这个问题是关于避免编码,而不是添加编码作为链接为重复状态的问题。

4

1 回答 1

4

“/v1/api.php”不是 的一部分host,而是path.

用这个:

var components = URLComponents()
components.scheme = "https"
components.host = "endpoint.com"
components.path = "/v1/api.php"
于 2019-07-07T09:35:14.710 回答