.NET Framework 使用System.Net.WebClient发送带有字符串有效负载的POST请求

示例

string requestUri = "http://www.example.com";
string requestBodyString = "请求正文字符串。";
string contentType = "text/plain";
string requestMethod = "POST";
    
byte[] responseBody;    
byte[] requestBodyBytes = Encoding.UTF8.GetBytes(requestBodyString);

using (var client = new WebClient())
{
    client.Headers[HttpRequestHeader.ContentType] = contentType;
    responseBody = client.UploadData(requestUri, requestMethod, requestBodyBytes);
}