C#的提交表单方式主要有两种WebClient与HttpWebRequest,这里先介绍一种
WebClient,转送门:http://msdn.microsoft.com/zh-cn/library/system.net.webclient(v=VS.80).aspx
- string postString = "arg1=a&arg2=b";
- byte[] postData = Encoding.UTF8.GetBytes(postString);
- string url = "http://localhost/register.php";//地址
- WebClient webClient = new WebClient();
- webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
- byte[] responseData = webClient.UploadData(url, "POST", postData);
- string srcString = Encoding.UTF8.GetString(responseData);
C#模拟POST提交表单(一)--WebClient
原文:http://www.cnblogs.com/soundcode/p/3934409.html