c# - 我在请求 https url 时收到错误远程服务器未找到

标签 c# windows-phone-8 youtube-api

我正在开发一个 Windows Phone 8 应用程序,它从 youtube 数据 api 获取视频源。我向 https://gdata.youtube.com/feeds/api/videos?max-results=10&v=2&alt=jsonc&q=fondoflamenco 发出了 httpWebRequest,但我收到错误远程服务器:未找到。我将 Windows Phone 8 设备连接到同一网络。

这是源代码:

Uri targetUri = new Uri("https://gdata.youtube.com/feeds/api/videos?max-results=10&v=2&alt=jsonc&q=fondoflamenco");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);
request.Method = "GET";
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);

ReadWebRequestCallback 的代码是:

        private void ReadWebRequestCallback(IAsyncResult callBackResult)
    {
        HttpWebRequest myRequest = (HttpWebRequest)callBackResult.AsyncState;
        try
        {
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callBackResult);
            using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
            {
                var results = httpwebStreamReader.ReadToEnd();
                JObject jsonObject = JObject.Parse(results);
                JArray items = JArray.FromObject(jsonObject["items"]);
                List<Video> videos = new List<Video>();
                foreach (var item in items)
                {
                    Video video = new Video();
                    video.descripcion = item["description"].ToString();
                    if (item["player"]["mobile"] != null)
                    {
                        video.url = item["player"]["mobile"].ToString();
                    }
                    video.imagen = new System.Windows.Media.Imaging.BitmapImage(new Uri(item["thumbnail"]["sqDefault"].ToString()));
                    videos.Add(video);
                }
                Dispatcher.BeginInvoke(delegate()
                {
                    MediaList.ItemsSource = videos;
                });

            }
        }
        catch (WebException ex)
        {
            //Dispatcher.BeginInvoke(delegate() { DescriptionBox.Text = ex.Message; });
            throw;
        }

    }

我在做什么导致远程服务器错误:未找到

最佳答案

我刚刚解决了它向 https 请求添加空凭证的问题,就像这样

    myRequest.Credentials = new NetworkCredential("", "");

这里他解释得更好

http://blog.toetapz.com/2010/11/15/windows-phone-7-and-making-https-rest-api-calls-with-basic-authentication/

关于c# - 我在请求 https url 时收到错误远程服务器未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25340557/

相关文章:

javascript - 窗口高度不变

c# - 使用 C# 和 Mono : IdentityMapper being used incorrectly 的 Hadoop 流式传输

c# - 在 C# 插件中更改业务流程阶段

c# - 双向文件夹同步加密以保护我的 Dropbox 数据

testing - 任何地方或论坛都可以帮助测试我的 Windows Phone 应用程序(.xap 文件)?

swift - 使用 swift 和 alamofire 将视频(和属性)上传到 YouTube

c# - Google 中的 URL 索引

windows-phone-8 - Windows Phone 8 连接处理程序/互联网可用性

windows-phone-8 - Windows Phone 8.1 透明磁贴

java - YouTube错误400缺少Prams API V3