**public string HttpPost1(string url, string body)
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; //一定要有这一句
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Accept = "text/html, application/xhtml+xml, */*";
request.ContentType = "application/json";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return reader.ReadToEnd();
}
}**
c# 访问https接口 Post方式
最新推荐文章于 2024-09-12 16:31:33 发布
本文深入讲解了使用C#发送HTTP POST请求的方法,包括设置安全协议、请求头、内容类型及编码,展示了如何构造请求体并读取响应结果,是理解和实践HTTP POST请求的实用指南。
1436

被折叠的 条评论
为什么被折叠?



