C#呼叫新浪微博API例項程式碼
阿新 • • 發佈:2020-01-07
C#呼叫新浪微博API
WebRequest wq = WebRequest.Create(this.address); HttpWebRequest hq = wq as HttpWebRequest; string username = "[email protected]"; string password = "3216731ks"; string appkey = "5786724301"; System.Net.CredentialCache cache = new CredentialCache(); cache.Add(new Uri(this.address),"Basic",new NetworkCredential(username,password)); hq.Credentials = cache; hq.Headers.Add("Authorization","Basic " +Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(username+":"+password))); System.Net.WebResponse webresponse = hq.GetResponse(); System.IO.Stream receiveStream = webresponse.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(receiveStream,System.Text.Encoding.UTF8); string json = reader.ReadToEnd();
以上程式碼例項很簡單,大家可以本地測試下,感謝你的閱讀和對我們的支援。