C# Can';无法发送此HttpWebRequest

C# Can';无法发送此HttpWebRequest,c#,httpwebrequest,C#,Httpwebrequest,我制作了一个弹出框,其中显示了Google验证码,例如: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 然后

我制作了一个弹出框,其中显示了Google验证码,例如:
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

然后我在我的程序中输入验证码,并将信息发送到下面的下一个函数,它应该将数据提交给谷歌。我试着用Fiddler追踪它,但我似乎不知道出了什么问题。请求只返回另一个验证码图像

在Fiddler中,当我进入浏览器并提交GET类型的请求时,我可以看到,但我如何向该浏览器提交数据?我试着把帖子换成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;
    }
publicstringsubmitgooglecaptcha(字符串html,字符串captchaCode)
{
CookieContainer cookieCont=新CookieContainer();
HttpWebRequest wReq;
HttpWebResponse_-wResp;
System.IO.StreamReader\u sr;
System.Text.asciencoding_enc=新的System.Text.asciencoding();
字符串continueValue=Regex.Match(html,@“”,RegexOptions.IgnoreCase).Groups[1]。值;
字符串idFromGoogle=Regex.Match(html,@“”,RegexOptions.IgnoreCase).Groups[1]。值;
字符串_html=“”;
string postData=“continue=“+continueValue+”&id=“+idFromGoogle+”&captcha=“+captchaCode+”&submit=submit”;
尝试
{
字节[]_数据=_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=“应用程序/x-www-form-urlencoded”;
_wReq.ContentLength=_data.Length;
_wReq.CookieContainer=cookieCont;
_wReq.AllowAutoRedirect=true;
_wReq.UserAgent=“Mozilla/5.0(兼容;MSIE 7.0;Windows NT 5.1;.NET CLR 1.1.4322;.NET CLR 2.0.50727)”;
System.IO.Stream _outStream=_wReq.GetRequestStream();
_超流写入(_data,0,_data.Length);
_exptream.Close();
_wResp=(HttpWebResponse)u wReq.GetResponse();
_sr=新的System.IO.StreamReader(_wResp.GetResponseStream());
_html=_sr.ReadToEnd();
_高级关闭();
_wResp.Close();
}
捕获(异常ee)
{
}
返回html;
}

当我尝试你发布的代码时,你会得到一个异常。如果您没有使用
catch(Exception ee){}
对自己隐藏所有异常,您就会知道。您得到的异常是,试图告诉您服务器发回503错误“服务器不可用”

我建议您学习一些基本的异常处理原则


另外,我在Fiddler中看到了请求。

该错误是否表示我提交到了错误的url?