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

相關問題