gpt4 book ai didi

ios - swift ios 中的 URL 编码问题

转载 作者:行者123 更新时间:2023-11-28 11:04:57 24 4
gpt4 key购买 nike

我从我的服务器响应中获取 url 为:

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

我正在编码为:

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

但是 avplayer 无法播放这个特定的 url。似乎是编码 URL 的一些问题

最佳答案

您的 URL 已经进行了百分比编码。

如果你再次编码,百分比部分将被编码两次,给出一个无效的 URL。

您可以通过从您的 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)

关于ios - swift ios 中的 URL 编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38345687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com