C#模拟POST表单提交 --- WebClient
string postString = "arg1=a&arg2=b";//这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来 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");//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可 byte[] responseData = webClient.UploadData(url, "POST", postData);//得到返回字符流 string srcString = Encoding.UTF8.GetString(responseData);//解码
来源:CSDN
作者:HOLD ON!
链接:https://blog.csdn.net/cxu123321/article/details/104647801