How to post data to specific URL using WebClient in C#

后端 未结 8 1640
深忆病人
深忆病人 2020-11-22 07:12

I need to use \"HTTP Post\" with WebClient to post some data to a specific URL I have.

Now, I know this can be accomplished with WebRequest but for some reasons I wa

8条回答
  •  日久生厌
    2020-11-22 07:51

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

    so here is the solution:

    string URI = "http://www.myurl.com/post.php";
    string myParameters = "param1=value1¶m2=value2¶m3=value3";
    
    using (WebClient wc = new WebClient())
    {
        wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
        string HtmlResult = wc.UploadString(URI, myParameters);
    }
    

    it works like charm :)

提交回复
热议问题