此时,我的以下代码每次都会返回 401 Unauthorized 错误:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://query.yahooapis.com/v1/yql?q=select%20fields.value%20from%20social.contacts%20where%20guid%3Dme&diagnostics=false");
request.Headers.Add(
"Authorization: OAuth " +
"realm=\"" + "yahooapis.com" + "\"," +
"oauth_consumer_key=\"" + ConfigurationManager.AppSettings["yahoo_oauth_consumer_key"] + "\"," +
"oauth_nonce=\"" + Guid.NewGuid().ToString() + "\"," +
"oauth_signature_method=\"" + "PLAINTEXT" + "\"," +
"oauth_timestamp=\"" + ((DateTime.UtcNow.Ticks - new DateTime(1970, 1, 1).Ticks) / (1000 * 10000)).ToString() + "\"," +
"oauth_token=\"" + accessToken.TokenValue + "\"," +
"oauth_version=\"1.0" + "\"," +
"oauth_signature=\"" + ConfigurationManager.AppSettings["yahoo_oauth_signature"] + "%26" + "\""
);
StreamReader streamReader = new StreamReader(request.GetResponse().GetResponseStream(), true);
当我每次进入代码时,我看到雅虎请求在标题中包含的所有信息,但每次我得到这个 401。