//用户验证数据
string username = "****";//微博登录名
string password = "****"; //微博登录密码
string usernamePassword = username + ":" + password;
//调用URL及POST数据
string url = "http://api.t.sina.com.cn/statuses/update.json"; string news_title = this.txtContent.Text;
int news_id = 62747;
string t_news = string.Format("{0},http://weibo.com/n/{1}/", news_title, news_id);
string data = "source=****&status=" + System.Web.HttpUtility.UrlEncode(t_news);
//准备用于发起请求的httpWebRequest对象: System.Net.WebRequest webrequet = System.Net.WebRequest.Create(url);
System.Net.HttpWebRequest httprequest = webrequet as System.Net.HttpWebRequest;
//准备用于用户验证的凭据:
System.Net.CredentialCache myCahe = new System.Net.CredentialCache();
myCahe.Add(new Uri(url), "Basic", new System.Net.NetworkCredential(username, password));
httprequest.Credentials = myCahe; httprequest.Headers.Add("Authorization", "Basic" + Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(usernamePassword)));
//发起POST请求
httprequest.Method = "POST";
httprequest.ContentType = "application/x-www-form-urlencoded"; System.Text.Encoding encoding = System.Text.Encoding.ASCII; byte[] bytesToPost = encoding.GetBytes(data); httprequest.ContentLength = bytesToPost.Length; System.IO.Stream requestStream = httprequest.GetRequestStream(); requestStream.Write(bytesToPost, 0, bytesToPost.Length); requestStream.Close();
//获取服务器端响应的内容
System.Net.WebResponse wr = httprequest.GetResponse(); //这行报403 错误,
System.IO.Stream receiveSteam = wr.GetResponseStream();
using (System.IO.StreamReader reader=new System.IO.StreamReader(receiveSteam,System.Text.Encoding.UTF8)) { string responeContent = reader.ReadToEnd(); }
----------------------------------------------------------------------------------
int news_id = 62747;
string t_news = string.Format("{0},http://news.cnblogs.com/n/{1}/", news_title, news_id );
news_id 应该填写什么内容,还有小括号里的ID 原文,借鉴
http://www.xueit.com/html/2010-05/21-1947494524201051310222846.html
请高手解答!