public string HttpPost()
{
HttpWebRequest webrequest =
(HttpWebRequest)HttpWebRequest.Create("接口地址");
webrequest.Method = "POST";
webrequest.ContentType = "application/x-www-form-urlencoded"; //无关的请求头在本文中都省略掉了
webrequest.Headers.Add("Access-Token", "Sinopec-Station");
string postData = “json串” ;
byte[] postdatabyte = Encoding.UTF8.GetBytes(postData);
webrequest.ContentLength = postdatabyte.Length;
Stream stream = webrequest.GetRequestStream();
stream.Write(postdatabyte, 0, postdatabyte.Length);
stream.Close();
HttpWebResponse response = (HttpWebResponse)webrequest.GetResponse();
Stream myResponseStream = response.GetResponseStream();
//StreamReader myStreamReader = new StreamReade
c# 调用post 请求
最新推荐文章于 2024-05-18 16:36:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)