do szybkiego 4
pierwszym jej lepiej używać tego rozszerzenia:
extension URL{
func withQueries(_ queries:[String:String]) -> URL? {
var components = URLComponents(url: self, resolvingAgainstBaseURL: true)
components?.queryItems = queries.flatMap{URLQueryItem(name: $0.0, value: $0.1)}
return components?.url
}
func justQueries(_ queries:[String:String]) -> URL? {
var components = URLComponents(url: self, resolvingAgainstBaseURL: true)
components?.queryItems = queries.flatMap{URLQueryItem(name: $0.0, value: $0.1)}
return components?.url
}
}
to rozszerzenie jest bardzo przydatna uchwyty parametrów i ich wartości. sekunda:
let urlstring = "https://yourdomain.com"
let url = URL(string: urlstring)!
let request = NSMutableURLRequest(url: url as URL)
request.httpMethod = "POST"
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
let query :[String:String] = ["username":"admin","password":"111"]
let baseurl = URL(string:urlstring)!
let postString = (baseurl.withQueries(query)!).query
request.httpBody = postString?.data(using: .utf8)
webview.load(request as URLRequest)
Testowany i działa, dzięki! –
działa dobrze. Pozdrawiam –
Myślę, że 'prośba' powinna zostać wydana na końcu. :) – Kjuly