我试图发布一个表单,但是当我查看返回的 html 代码时我一直收到错误消息
必须启用 Cookie 才能提交表单
我使用以下代码提交表单:
string postData = "submit_hidden=submit_hidden&captcha_item_key=" + captcha_item_key + "&security_code=" + lastCaptcha + "&submit=Submit";
byte[] _data = _enc.GetBytes(postData);
_wReq = (HttpWebRequest)WebRequest.Create(urlen);
_wReq.Referer = urlen;
_wReq.CookieContainer = myContainer;
_wReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
_wReq.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
_wReq.Headers.Add("Accept-Language", "sv-SE,sv;q=0.8,en-US;q=0.6,en;q=0.4");
_wReq.KeepAlive = true;
_wReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
_wReq.Method = "POST";
_wReq.ContentType = "application/x-www-form-urlencoded";
_wReq.ContentLength = _data.Length;
System.IO.Stream _outStream = _wReq.GetRequestStream();
_outStream.Write(_data, 0, _data.Length);
_outStream.Close();
_wResp = (HttpWebResponse)_wReq.GetResponse();
_sr = new System.IO.StreamReader(_wResp.GetResponseStream());
_respStr = _sr.ReadToEnd();
_sr.Close();
_wResp.Close();
我将 cookie 保存到 cookie 容器中,所以我不确定它为什么不起作用?
Javascript 不是问题,因为我试图在没有激活 Javascript 的情况下从浏览器提交表单。
还检查了 Fiddler 的提交,唯一与使用我的方法的浏览器不同的是 cookie 出于某种原因没有正确设置。
有任何想法吗?