首页 新闻 会员 周边 捐助

C#发一条新的微博

0
悬赏园豆:50 [已关闭问题] 关闭于 2011-06-28 11:55

  string username = "fanjiaxing@hotmail.com";
            string password = "XXXXXX";
            string usernamePassword = username + ":" + password;

            //准备调用的URL及需要POST的数据:

            string url = "http://api.t.sina.com.cn/statuses/update.xml?source = 1776XXXXXX&status= test!";
            //string content = "新的一天新的开始!";
            //准备用于发起请求的HttpWebRequest对象
            WebRequest webRequest = WebRequest.Create(url);
            HttpWebRequest httpRequest = webRequest as HttpWebRequest;
            //准备用于用户验证的凭据
            CredentialCache myCache = new CredentialCache();
            myCache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
            httpRequest.Credentials = myCache;
            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;

            WebResponse wr = httpRequest.GetResponse();
            Stream receiveStream = wr.GetResponseStream();
            using (StreamReader reader = new StreamReader(receiveStream, System.Text.Encoding.UTF8))
            {
                string responseContent = reader.ReadToEnd();
            }

为什么WebResponse wr = httpRequest.GetResponse();
返回远程服务器返回错误: (400) 错误的请求。在线等!

天添的主页 天添 | 初学一级 | 园豆:178
提问于:2011-06-28 11:25
< >
分享
所有回答(1)
0

我也总是遇到这个问题,但是没有高手解决啊。

悟行 | 园豆:12559 (专家六级) | 2011-11-02 19:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册