macOS, iOS

[iOS] '?' 을 써서, url에 넣을 때 인코딩이 안되는 문제 해결하기

SweetDev 2019. 12. 14. 20:35

후 내 4시간 돌려줘요...

 

"

Because the ? isn't part of a path. It's a separator to signal the beginning of the query string. You can read about the different components of a URL in this article. Each component has its set of valid characters, anything not in that set needs to be percent-escaped. The best option is to use URLComponentswhich handles the escaping automatically for you:

"

 

var urlComponents = URLComponents(string: MyRouter.baseURLString)!

urlComponents.queryItems = [ URLQueryItem(name: "username", value: "jsmith"), URLQueryItem(name: "password", value: "password") ]

let url = urlComponents.url!