POST请求——HttpWebRequest
string url=""; string param=""; string result = string.Empty; HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); Encoding encoding = Encoding.UTF8; byte[] bs = Encoding.UTF8.GetBytes(param); string responseData = String.Empty; req.Method = "Post"; req.Accept = "application/json, text/javascript, */*; q=0.01"; req.ContentType = "application/json; charset=UTF-8"; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); reqStream.Close(); } using (HttpWebResponse response = (HttpWebResponse)req.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { responseData = reader.ReadToEnd().ToString(); } result = responseData; }
学习技术最好的文档就是【官方文档】,没有之一。
还有学习资料【Microsoft Learn】、【CSharp Learn】、【My Note】。
如果,你认为阅读这篇博客让你有些收获,不妨点击一下右下角的【推荐】按钮。
如果,你希望更容易地发现我的新博客,不妨点击一下【关注】。