我想发送这样的请求
GET /v1/contacts?sid=msgrsessionid
Authorization: OAuth
realm="yahooapis.com",
oauth_consumer_key="dj0yJmk9nM9Y29uc3VtZXJzZWNyZXQmeD1lMg--",
oauth_nonce="24829.2331",
oauth_signature_method="PLAINTEXT",
oauth_timestamp="1219450170",
oauth_token="A%3DuqkiebGpiTJl7ThQxU.jDXXaETYyfEy3xAKPyoavokwOOcZcz8Xs_l1Nvnl._KmCEVCeLkxxT1Y6BgRqf5f98sQWHklBM_anetveR7okK_M_5XEmQ1_1reo3UgKQULT_dQT8Gao3rgz5rJxgmnYrhdWWdfgTdMQVzpbJT2aGkz59NTK1O8yXVE1EvZUCqju7WiFYu.WHNEw.9TWq3g--",
oauth_version="1.0",
oauth_signature="O2AQipLITO0aYHKZc9266RzC94%260af0ef7f79bfb89dd6af87589e4c97b022f594a3"
我正在使用下面的代码,但我得到未经授权的访问(401)异常,这里有什么问题以及如何将上述原始请求作为字符串发送(就像我们使用 telnet 所做的那样)而不是构造为 WebRequest。
Uri address = new Uri("https://api.login.yahoo.com/oauth/v2/get_token");
WebRequest request = WebRequest.Create(address);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
StringBuilder authHeader = new StringBuilder();
authHeader.Append("Authorization: OAuth ");
authHeader.Append("realm=\"yahooapis.com\", ");
authHeader.Append("oauth_consumer_key=\""+consumerKey+"\", ");
authHeader.Append("oauth_nonce=\""+random+"\", ");
authHeader.Append("oauth_signature_method=\"PLAINTEXT\", ");
authHeader.Append("oauth_timestamp=\""+UnixTimeNow().ToString()+"\", ");
authHeader.Append("oauth_token=\""+requestToken.Trim()+"\", ");
authHeader.Append("oauth_version=\"1.0\", ");
authHeader.Append("oauth_signature=\""+HttpUtility.UrlEncode(consumerKey+"&"+consumersecret)+"\"");
request.Headers.Add(authHeader.ToString());