Sending a POST request with a string payload using System.Net.HttpWebRequest
suggest changestring requestUri = "http://www.example.com";
string requestBodyString = "Request body string.";
string contentType = "text/plain";
string requestMethod = "POST";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
request.Method = requestMethod;
request.ContentType = contentType;
byte[] bytes = Encoding.UTF8.GetBytes(requestBodyString);
using (Stream stream = request.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents