[英]URL Encoding issue in swift ios
我從服務器響應中獲取的網址為:
https://baseURL/The+Man+in+the+High+Castle+Official+Trailer+%E2%80%93+2+th.m3u8
我正在編碼為:
videoURL = videoURL.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
但是avplayer無法播放此特定網址。 似乎在編碼網址時出現問題
您的網址已進行百分比編碼。
如果再次對其進行編碼,則百分比部分將被編碼兩次,從而給出無效的URL。
您可以通過從網址中刪除百分比編碼並再次進行設置來查看:
let base = "https://baseURL/The+Man+in+the+High+Castle+Official+Trailer+%E2%80%93+2+th.m3u8"
let decoded = base.stringByRemovingPercentEncoding!
print(decoded)
let encoded = decoded.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLFragmentAllowedCharacterSet())!
print(encoded)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.