nsurlcomponents

URLComponents queryItems losing percent encoding when mutated

故事扮演 提交于 2019-12-11 04:25:24
问题 When using URLComponents 's queryItems I've found that if you have a query item whose value contains some percent encoded characters, in my case a / being encoded as %2F , then if you construct a URLComponents object from a String URL that contains such a query item, then mutate the list of query items for the URLComponents object, then if you try to get a URL by calling .url on the URLComponents object, then the query items lose their percent encoding. Here's the code I've been testing this

URLComponents.url is nil

时光毁灭记忆、已成空白 提交于 2019-11-29 16:04:55
问题 I'm trying to use URLComponents to compose a URL as that appears to be what it's for. However, when I then access the url property of the components it is nil. Example... var urlComponents = URLComponents(string: "http://google.com")! urlComponents.path = "auth/login" Then I do ... print(urlComponents) Output... scheme: http host: google.com path: auth/login - scheme : "http" - host : "google.com" - path : "auth/login" But then... print(urlComponents.url) outputs nil . Am I doing something