比照着网上提供的一些代码:自己写了一下,但是老是出现错误:无法发送具有此谓词类型的内容正文。一直提示这个错误,那位高手看一下我的代码那里有问题,求指导!
string url = "http://localhost:30747/WebForm1.aspx";
string __VIEWSTATE = "/wEPDwUKLTg0OTIzODQwNWRkQrsiVjjfcttD1psiP9pESun/JH4=";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string postData = "__VIEWSTATE=" + __VIEWSTATE + "&txt1=admin&txt2=admin&btnOK=ok";
byte[] b = Encoding.UTF8.GetBytes(postData);
request.ContentLength = b.Length;
Stream stream = request.GetRequestStream();
stream.Write(b, 0, b.Length);
改成这样试试:
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
不妨把上面的这行代码放到下面的这行代码后面试试:
stream.Write(b, 0, b.Length);