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

后端 未结 8 1541
深忆病人
深忆病人 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:56

    string URI = "site.com/mail.php";
    using (WebClient client = new WebClient())
    {
        System.Collections.Specialized.NameValueCollection postData = 
            new System.Collections.Specialized.NameValueCollection()
           {
                  { "to", emailTo },  
                  { "subject", currentSubject },
                  { "body", currentBody }
           };
        string pagesource = Encoding.UTF8.GetString(client.UploadValues(URI, postData));
    }
    

提交回复
热议问题