我有这个代码,试图验证与雅虎!它在我的本地服务器上正常工作,但在我的实时服务器上发出的请求失败。当它调用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'或询问您的网络管理员。 –