【问题标题】:I get error remote server not found with a request to https url我收到错误远程服务器未找到对 https url 的请求
【发布时间】:2014-08-16 13:18:58
【问题描述】:

我正在开发一个从 youtube 数据 api 获取视频源的 windows phone 8 应用程序。我向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;
        }

    }

我在做什么以获取远程服务器错误:未找到

【问题讨论】:

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


    【解决方案1】:

    我刚刚解决了它向 https 请求添加空凭据,像这样

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

    他在这里解释得更好

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-02
      • 1970-01-01
      • 2014-02-02
      • 2021-02-03
      • 2014-11-28
      • 2019-03-01
      相关资源
      最近更新 更多