我已經顯示從例如谷歌驗證碼的彈出框:http://www.google.com/sorry/?continue=http://www.google.com/ajax/rd%3Fsky%3Deeuiphp%26ludocid%3D6083833001863340802%26rdu%3DCNzphIbM6rECFWkGtAodP3UAGQ%26sig%3DaY3%26q%3Dtandl%25C3%25A4kare%252Cg%25C3%25B6teborg%2BSweden
無法發送此HttpWebRequest的
我然後在驗證碼輸入到我的計劃之內框和發送信息發給我的下一個函數下面,它應該提交數據給谷歌。我試圖用Fiddler跟蹤它,但我似乎無法弄清楚什麼是錯誤的。該請求只是返回另一個驗證碼圖像。
在Fiddler中,我可以看到何時進入瀏覽器並提交GET請求的請求,但是如何將數據提交給該提示?我試着將我的POST切換到GET等,但總是得到相同的錯誤,只是另一個驗證碼圖像。
任何想法可能是錯的?
public string submitGoogleCaptcha(string html, string captchaCode)
{
CookieContainer cookieCont = new CookieContainer();
HttpWebRequest _wReq;
HttpWebResponse _wResp;
System.IO.StreamReader _sr;
System.Text.ASCIIEncoding _enc = new System.Text.ASCIIEncoding();
string continueValue = Regex.Match(html, @"<input type=""hidden"" name=""continue"" value=""\s*(.+?)\s*"">", RegexOptions.IgnoreCase).Groups[1].Value;
string idFromGoogle = Regex.Match(html, @"<input type=""hidden"" name=""id"" value=""\s*(.+?)\s*"">", RegexOptions.IgnoreCase).Groups[1].Value;
string _html = "";
string postData = "continue=" + continueValue + "&id=" + idFromGoogle + "&captcha=" + captchaCode + "&submit=Submit";
try
{
byte[] _data = _enc.GetBytes(postData);
_wReq = (HttpWebRequest)WebRequest.Create("http://www.google.com/sorry/Captcha?");
_wReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
_wReq.Referer = "http://www.google.com/sorry/?continue=" + HttpUtility.UrlEncode(continueValue);
_wReq.KeepAlive = true;
_wReq.Method = "POST";
_wReq.ContentType = "application/x-www-form-urlencoded";
_wReq.ContentLength = _data.Length;
_wReq.CookieContainer = cookieCont;
_wReq.AllowAutoRedirect = true;
_wReq.UserAgent = "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
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());
_html = _sr.ReadToEnd();
_sr.Close();
_wResp.Close();
}
catch (Exception ee)
{
}
return _html;
}
這個錯誤是否表明我提交給錯誤的URL? – gwenda 2012-08-16 13:26:45