日期:2014-05-18  浏览次数:20723 次

新浪微博 oauth授权 发送微博
Uri uri = new Uri("http://api.t.sina.com.cn/statuses/update.xml");
  string nonce = oAuth.GenerateNonce();
  string timeStamp = oAuth.GenerateTimeStamp();
  string normalizeUrl, normalizedRequestParameters;
  // 签名
  string sig = oAuth.GenerateSignature(
  uri,
  apiKey,
  apiKeySecret,
  Session["oauth_token"].ToString(),
  Session["oauth_token_secret"].ToString(),
  "Get",
  timeStamp,
  nonce,
  string.Empty,
  out normalizeUrl,
  out normalizedRequestParameters);
  sig = HttpUtility.UrlEncode(sig);
  StringBuilder sb = new StringBuilder(uri.ToString());
  sb.AppendFormat("?oauth_consumer_key={0}&", apiKey);
  sb.AppendFormat("oauth_nonce={0}&", nonce);
  sb.AppendFormat("oauth_timestamp={0}&", timeStamp);
  sb.AppendFormat("oauth_signature_method={0}&", "HMAC-SHA1");
  sb.AppendFormat("oauth_version={0}&", "1.0");
  sb.AppendFormat("oauth_signature={0}&", sig);
  sb.AppendFormat("oauth_token={0}&", Session["oauth_token"].ToString());
  sb.Append("status=" + System.Web.HttpUtility.UrlEncode("123456") + "");
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sb.ToString());
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  StreamReader stream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
  string responseBody = stream.ReadToEnd();
  stream.Close();
  response.Close();

一直报401不知道为什么。
请大虾帮忙看一下
分数不高,多谢了

------解决方案--------------------
用户名密码等认证信息对吗