我正在尝试格式化用于访问API的URL。 api的文档指定了一个包含“[”和“]”字符的URL。当我在Swift中从我的字符串创建一个URL时,它会添加百分比编码并将这些字符更改为“%5B”和“%5D”。
如何告诉swift不对这些字符进行百分比编码?谢谢!
func attemptPubgIDLookup (playerName: String, completion: @escaping (String) -> Void) {
let region = "pc-na"
let urlString = "https://api.playbattlegrounds.com/shards/" + region + "/players?filter[playerNames]=" + playerName
let finalUrl = URL(string:urlString)
if let finalUrl = finalUrl {
var urlRequest = URLRequest(url: finalUrl)
urlRequest.httpMethod = HTTPMethod.get.rawValue
urlRequest.addValue(pubgApiKey, forHTTPHeaderField: "Authorization: Bearer")
urlRequest.addValue("application/vnd.api+json", forHTTPHeaderField: "Accept")
Alamofire.request(urlRequest)
.responseJSON(completionHandler: { (response) in
debugPrint(response)
})
}
}
答案 0 :(得分:1)