How do I use WebClient to send NET/C-sharp data to a specified remote request address in the development of a (POST) application?

during the development of a .NET / C-sharp application, you need to use the WebClient class to send (HTTP POST) data to the specified remote request address.

of course, instead of using the class WebClient, we can use WebRequest to send HTTP requests, but if for certain reasons, we must use WebClient to handle it, how should it be implemented, and what is the way to do it?


use WebClient, then set the ContentType of the request header to application/x-www-form-urlencoded, and then call the UploadString () method of the WebClient instance, as follows:

string URI = "http://www.myurl.com/post.php";
string myParameters = "param1=value1&param2=value2&param3=value3";

using (WebClient wc = new WebClient())
{
    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    string HtmlResult = wc.UploadString(URI, myParameters);
}
For more solutions, please refer to .How do I use WebClient to send (POST) data to a specified remote request address in NET/C-sharp application development?

Menu