gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 18:28:16 25 4
gpt4 key购买 nike

我正在开发一个 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/

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