我有一个。我正在从特定播放列表中提取视频的ASP.net Web应用程序。在本地我没有问题,但是当我以1and1发布到我的网站时,出现错误。我遇到了2种不同的错误,试图以两种不同的方式调用API。 他们来了: 第一种方法:
WebRequest req = WebRequest.Create("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=" + maxResults + "&playlistId=PLdbTdTEwL-G7iMNYr-C0PqYm3YC2kByf3&key=" + myKey"); //Sends the get to YouTube API
WebResponse rep = req.GetResponse();
Stream dataStream = rep.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string result = reader.ReadToEnd();
//Close streams
rep.Close();
reader.Close();
dataStream.Close();
//Convert from json to C#
JObject finishedString = JObject.Parse(result);
IList<JToken> myJsonObject = finishedString["items"].Children().ToList(); //Grab all data from items and put it in json object
IList<Item> searchResults = new List<Item>(); //The default class where most of the info is at
foreach (JToken item in myJsonObject)
{
var videoData = item.ToObject<Item>();
searchResults.Add(videoData);
}
然后,当我发布并尝试访问该页面时,出现以下错误集: 操作已超时 说明:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
异常详细信息:System.Net.WebException:操作已超时
源错误:
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。
堆栈跟踪:
[WebException:操作已超时]
System.Net.HttpWebRequest.GetResponse()+1399
C:\ Users \ Aaron Craig \ Desktop \ steadystatestudios_website \ SteadyStateStudios \ SteadyStateStudios \ Controllers \ HomeController.cs中的SteadyStateStudios.Controllers.HomeController.Weddings()
lambda_method(Closure,ControllerBase,Object [])+62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object []参数)+14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary 2 parameters) +157
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2个参数)+27
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult,ActionInvocation innerInvokeState)+22
System.Web.Mvc.Async.WrappedAsyncResult 2.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+49
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d()+50
System.Web.Mvc.Async。<> c__DisplayClass46.b__3f()+228
System.Web.Mvc.Async。<> c__DisplayClass33.b__32(IAsyncResult asyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+49
System.Web.Mvc.Async。<> c__DisplayClass2b.b__1c()+26
System.Web.Mvc.Async。<> c__DisplayClass21.b__1e(IAsyncResult asyncResult)+100
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+44
System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult,ExecuteCoreState innerState)+13
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+38
System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult,控制器控制器)+12
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+28
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult,ProcessRequestState innerState)+21
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9874049
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep步骤)+48
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值并已完成同步)+159
然后,当我以这种方式尝试时:
var client = new RestClient("https://www.googleapis.com/youtube/v3/playlistItems");
var request = new RestRequest();
if (ViewBag.isMobile == true)
{
request = new RestRequest("?part=snippet&maxResults=3&playlistId=PLdbTdTEwL-G7iMNYr-C0PqYm3YC2kByf3&key=AIzaSyCaZlL6E-t6Cficmt1NFrKwwENmgaOBIC4");
}
else
{
request = new RestRequest("?part=snippet&maxResults=6&playlistId=PLdbTdTEwL-G7iMNYr-C0PqYm3YC2kByf3&key=AIzaSyCaZlL6E-t6Cficmt1NFrKwwENmgaOBIC4");
}
IRestResponse<RootObject> response = client.Execute<RootObject>(request);
IList<Snippet> videos = new List<Snippet>();
foreach(var item in response.Data.items)
{
videos.Add(item.snippet);
}
使用该代码,我得到此错误: “ /”应用程序中的服务器错误。 你调用的对象是空的。 说明:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
源错误:
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。
堆栈跟踪:
[NullReferenceException:对象引用未设置为对象的实例。]
C:\ Users \ Aaron Craig \ Desktop \ steadystatestudios_website \ SteadyStateStudios \ SteadyStateStudios \ Controllers \ HomeController.cs:75中的SteadyStateStudios.Controllers.HomeController.Weddings()
lambda_method(Closure,ControllerBase,Object [])+62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object []参数)+14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary 2 parameters) +157
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2个参数)+27
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult,ActionInvocation innerInvokeState)+22
System.Web.Mvc.Async.WrappedAsyncResult 2.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+32
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d()+50
System.Web.Mvc.Async。<> c__DisplayClass46.b__3f()+228
System.Web.Mvc.Async。<> c__DisplayClass33.b__32(IAsyncResult asyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+34
System.Web.Mvc.Async。<> c__DisplayClass2b.b__1c()+26
System.Web.Mvc.Async。<> c__DisplayClass21.b__1e(IAsyncResult asyncResult)+100
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+27
System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult,ExecuteCoreState innerState)+13
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+36
System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult,控制器控制器)+12
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult,ProcessRequestState innerState)+21
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9874049
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep步骤)+48
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值并已完成同步)+159
我全神贯注。不同的错误,不同的代码。本地没问题。而且我不认为它位于1and1上,但也许是。 感谢您的帮助。