Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
swift-ios中的URL编码问题_Ios_Swift_Avplayer_Url Encoding - Fatal编程技术网

swift-ios中的URL编码问题

swift-ios中的URL编码问题,ios,swift,avplayer,url-encoding,Ios,Swift,Avplayer,Url Encoding,我从服务器响应中获取url,如下所示: 我的编码方式如下: videoURL = videoURL.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())! 但是avplayer无法播放此特定url。 似乎在编码URL时出现了一些问题您的URL已进行了百分比编码 如果再次编码,百分比部分将被编码两次,从而给出无效的URL 通过从URL中删除百分比编码并重

我从服务器响应中获取url,如下所示:

我的编码方式如下:

 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)

您的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)

当您已经对字符串进行了编码时,为什么要使用“stringByAddingPercentEncodingWithAllowedCharacters”。只需使用简单的字符串附加。当您已经对字符串进行了编码时,为什么要使用“stringByAddingPercentEncodingWithAllowedCharacters”。只需使用简单的字符串append。完美的理由!!双重编码是问题所在。。。非常感谢它帮助我解决了一年来的问题,真是感激不尽。。鞠躬:)@DhavalH.Nena啊!不客气。我很高兴这有帮助。完美的理由!!双重编码是问题所在。。。非常感谢它帮助我解决了一年来的问题,真是感激不尽。。鞠躬:)@DhavalH.Nena啊!不客气。我很高兴这有帮助。