Swift URL指定字符encoding

2020-05-22  本文已影响0人  艾欧尼亚
1.指定支付encoding
["/","=","?","&"].forEach({ (char) in
    let custom = CharacterSet(charactersIn: char).inverted
    lastPath = lastPath.addingPercentEncoding(withAllowedCharacters: custom) ?? ""
})
2.指定字符不被encoding
var charSet = CharacterSet.urlQueryAllowed
["#"].forEach({ (char) in
    charSet.insert(charactersIn: char)
})
url = url.addingPercentEncoding(withAllowedCharacters: charSet)!
上一篇下一篇

猜你喜欢

热点阅读