新浪微博 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
请各位帮忙看一下.
谢谢
------解决方案--------------------
用html代码模拟,然后看一下具体是什么错,然后根据错误修改代码:
<form id="form1" runat="server" method="post" action="http://api.t.sina.com.cn/statuses/update.xml">
<div>
<input name="必填参数1" type="text" value="必填参数1的值" />
<input name="必填参数2" type="text" value="必填参数2的值" />
<input name="必填参数3" type="text" value="必填参数3的值" />
<input type="submit" value="测试" />
</div>
</form>