我有這個代碼,試圖驗證與雅虎!它在我的本地服務器上正常工作,但在我的實時服務器上發出的請求失敗。當它調用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();
您的服務器是否是代理服務器? –
我不確定。我該如何檢查? – brenjt
從您的實時服務器的命令提示符輸入'ping www.yahoo.com'或詢問您的網絡管理員。 –