且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 C# 中使用 WebClient 将数据发布到特定 URL

更新时间:2023-11-26 20:00:40

我刚刚找到了解决方案,是的,它比我想象的要容易 :)

I just found the solution and yea it was easier than I thought :)

所以这是解决方案:

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);
}

它的作用就像魅力:)