C# Post请求数据
/// <summary> /// 获取access_token /// </summary> /// <returns></returns> public string GetToken() { string url = "https://XXX.com/oauth/token?client_id=XX";
byte[] data = System.Text.Encoding.UTF8.GetBytes("");//参数
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Headers["Authorization"] = "XX"; //添加头 myRequest.Method = "POST";//请求类型 Get,Post.... myRequest.ContentType = "application/xml;charset=UTF-8";//内容格式
myRequest.ContentLength = data.Length; Stream newStream = myRequest.GetRequestStream(); newStream.Write(data, 0, data.Length); newStream.Close(); HttpWebResponse myResponse = myRequest.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); string content = reader.ReadToEnd(); reader.Close(); return content; }