简体   繁体   English

Swift iOS中的URL编码问题

[英]URL Encoding issue in swift ios

I am getting url from my server response as: 我从服务器响应中获取的网址为:

https://baseURL/The+Man+in+the+High+Castle+Official+Trailer+%E2%80%93+2+th.m3u8 https://baseURL/The+Man+in+the+High+Castle+Official+Trailer+%E2%80%93+2+th.m3u8

and i am doing encoding as : 我正在编码为:

 videoURL = videoURL.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!

but avplayer not able to play this particular url . 但是avplayer无法播放此特定网址。 seems like some issue in encoding URL 似乎在编码网址时出现问题

Your URL is already percent-encoded. 您的网址已进行百分比编码。

If you encode it again, the percent parts will be encoded twice, giving an invalid URL. 如果再次对其进行编码,则百分比部分将被编码两次,从而给出无效的URL。

You can see that by removing the percent encoding from your URL and setting it again: 您可以通过从网址中删除百分比编码并再次进行设置来查看:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM