本站大部分功能不支持IE浏览器,请使用谷歌内核的浏览器进行访问。

C# HttpWebRequest POST 简单例子

C# HttpWebRequest POST  简单例子

C# HttpWebRequest 简单例子

string URL="http://www.yuantk.com";
string PostStr="一个不专业的.NET开发者博客";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "post";//post方式
request.Accept = "text/html, application/xhtml+xml, */*";
request.ContentType = "application/x-www-form-urlencoded";
byte[] buffer = encoding.GetBytes(PostStr);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using( StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(strEncoding)))
{
           return reader.ReadToEnd();//返回请求得到的字符串
}
转载请注明原链接: https://www.yuantk.com/weblog/6b5e5878-e215-4b26-b852-a1fca57d86b4.html