如何在通用应用程序中下载youtube视频

本文关键字:下载 youtube 视频 应用程序 | 更新日期: 2023-09-27 18:00:10

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(videoInfoUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
string videoInfo = HttpUtility.HtmlDecode(reader.ReadToEnd());
NameValueCollection videoParams = HttpUtility.ParseQueryString(videoInfo);

我的代码:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(videoInforUrl);
           // HttpWebResponse response = await (HttpWebResponse)request.GetResponseAsync();
            //Stream responseStream = response.GetResponseStream();
            //StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
            //string videoInfor=HttpUtility

我收到了HttpWebResponse response = await (HttpWebResponse)request.GetResponseAsync();节目cannot convert httpwebresponse -> getresponseAsynce的问题。

HttpUtility 中不支持的通用应用程序上

如何在通用应用程序中下载youtube视频

不要强行输入。只要你能用它做你想做的事,就允许它返回它想要的东西。

去掉这样的显式类型,你就可以了:

var request = WebRequest.Create(videoInfoUrl);
var response = await request.GetResponseAsync();

发生错误的原因可能是(HttpWebResponse)位于错误的位置。如果你有,它会试图将Task,即GetResponseAsync转换为响应,这就是为什么你会得到这个错误。