2011-08-23 85 views
0

我有这个代码,试图验证与雅虎!它在我的本地服务器上正常工作,但在我的实时服务器上发出的请求失败。当它调用GetResponse()时,会返回(401)未经授权的错误。任何人都可以帮我理解为什么?如果您需要更多信息,请与我们联系。Yahoo,OAuth http请求。适用于本地主机,但不是活的服务器

try 
{ 
    string url = "https://api.login.yahoo.com/oauth/v2/get_request_token?oauth_callback=" + Server.UrlEncode("http://www.dowdlefolkart.com/extensions/contacts/webform1.aspx"); 
    url = GetUrl(url, consumerKey, consumerSecret); 

    var req = System.Net.HttpWebRequest.Create(url); 
    using (var res = req.GetResponse().GetResponseStream()) 
    { 
     .... 
    } 
} 
catch (Exception ex) 
{ 
    Response.Write("ERROR" + ex.Message); 
} 

以下是完整的错误异常:

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized. 
at System.Net.HttpWebRequest.GetResponse() 
at NopSolutions.NopCommerce.Web.Extensions.Contacts.WebForm1.Page_Load(Object sender, EventArgs e) 
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) 
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) 
at System.Web.UI.Control.OnLoad(EventArgs e) 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.HandleError(Exception e) 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest() 
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) 
at System.Web.UI.Page.ProcessRequest(HttpContext context) 
at ASP.extensions_contacts_webform1_aspx.ProcessRequest(HttpContext context) 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

更新:

我收到此错误使用Fiddler。

oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1314119105-1314120305

所以它看起来像从活的服务器我的时间戳是不正确的。这是我正在创建的时间戳:

string timestamp = Math.Floor((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();

+0

您的服务器是否是代理服务器? –

+0

我不确定。我该如何检查? – brenjt

+0

从您的实时服务器的命令提示符输入'ping www.yahoo.com'或询问您的网络管理员。 –

回答

1

我发现这个问题。错误的原因是由于无效的时间戳。它只比允许的大一点。使用Fiddler我能够确定这个问题。错误是:oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1314119105-1314120305

然后我登录到我的实时服务器,并将系统时钟调整到所需的状态。显然它快了15分钟。一旦我调整了这个错误消失。谢谢@Darin Dimitrov的帮助。

+0

真的是因为时间戳吗?我遇到了类似的问题,但我正在使用桌面上的本地Java应用程序测试我的应用程序,我需要在何处匹配时间戳? – xybrek

相关问题