kAzek napisał(a)
Obrazek jest inny (nie wiem dlaczego) ale mimo wszystko powinno działać. Coś musisz robić nie tak. Może nie takie nagłówki wysyłasz albo może ciacha mają coś do tego i coś nie tak z nimi :/
Nie no, skoro obrazek jest inny, to nie ma prawa działać.
Oto moja metoda, która robi wszystko jak być powinno i dupa, nie działa (The string you entered for the image verification did not match what was displayed.). W jaki sposób Firebug odczytuje adres tego obrazka? Gdy kliknę prawym na obrazek i zbadaj element, to elegancko pokazuje :(. Tutaj kod mojej metody, eh:
public void WriteNewTopic(string subject, string message)
{
// GET - pobranie strony formularza, w celu wyciągnięcia tokenu zabezpieczającego
_webRequest = (HttpWebRequest) WebRequest.Create(this.Url + "newthread.php?do=newthread&f=" + AppsId);
_webRequest.Method = "GET";
_webRequest.Headers["Cookie"] = this.Cookie;
_webRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0";
_webRequest.ContentType = "application/x-www-form-urlencoded";
_webRequest.KeepAlive = true;
_webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
_webRequest.Referer = this.Url + "viewforum.php?f=" + this.AppsId;
_webRequest.AllowAutoRedirect = true;
// Odpowiedź serwera
HttpWebResponse response = null;
try
{
response = (HttpWebResponse) _webRequest.GetResponse();
}
catch (WebException webException)
{
MessageBox.Show("Wystąpił błąd serwera: " + webException.Response);
return;
}
StreamReader reader = new StreamReader(response.GetResponseStream());
string sourceCode = reader.ReadToEnd();
// Wyciąganie tokenu
Match match = Regex.Match(sourceCode, "var SECURITYTOKEN = \"(.*)\""); // var SECURITYTOKEN = "1301771420-354a766e96ce7e3922e2e73eaa3ebc2bca5b4ff9";
string securityToken = match.Groups[1].ToString();
Regex rgx = new Regex("challenge.k=(.[^ ]{40})");
Match matchCaptchaJavaScript = rgx.Match(sourceCode);
string matchCaptchaJavaScriptUrl = matchCaptchaJavaScript.Groups[1].ToString();
string noscriptUrl = "http://www.google.com/recaptcha/api/challenge?k=" + matchCaptchaJavaScriptUrl;
// Wyciągnięcie adresu obrazka
_webRequest = (HttpWebRequest)WebRequest.Create(noscriptUrl);
_webRequest.Method = "GET";
_webRequest.Headers["Cookie"] = this.Cookie;
_webRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0";
_webRequest.ContentType = "application/x-www-form-urlencoded";
_webRequest.KeepAlive = true;
_webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
_webRequest.Referer = this.Url + "viewforum.php?f=" + this.AppsId;
_webRequest.AllowAutoRedirect = true;
// Odpowiedź serwera
HttpWebResponse response2 = null;
try
{
response2 = (HttpWebResponse)_webRequest.GetResponse();
}
catch (WebException webException)
{
MessageBox.Show("Wystąpił problem z odczytem reCaptcha: " + webException.Response);
}
StreamReader reader2 = new StreamReader(response2.GetResponseStream());
string sourceCode2 = reader2.ReadToEnd();
// challenge : '03AHJ_VutwWaXxLQ3Aj0fWYorSZ8XvskGWCSef5vB5MHFVb8_HpIZgXt1nabbzMV582mVjHpiU3Yafm3PM0QPO2SFMdXFGzr0mKg2p-bJxE3s7DxNAyPXJK3kkIjSeLZZrfs4SWc68P2Q4XS8taXbFgDr8Gq_73diEKg'
Match recaptchaChallengeField = Regex.Match(sourceCode2, "challenge : '(.+)'");
string recaptchaChallenge = recaptchaChallengeField.Groups[1].ToString();
string recaptchaImageAddress = "http://www.google.com/recaptcha/api/image?c=" + recaptchaChallenge;
WebClient webClient = new WebClient();
webClient.DownloadFile(recaptchaImageAddress, "lastRecaptcha.jpg");
reCaptchaReader reCaptchaReaderForm = new reCaptchaReader();
reCaptchaReaderForm.ShowDialog();
string recaptchaImageCode = reCaptchaReaderForm.Code;
// ------------------------------------------------------------
// POST - wysłanie formularza
_webRequest = (HttpWebRequest) HttpWebRequest.Create(this.Url + "newthread.php?do=newthread&f=" + AppsId);
_webRequest.Method = "POST";
_webRequest.Headers["Cookie"] = this.Cookie;
_webRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0";
_webRequest.ContentType = "application/x-www-form-urlencoded";
_webRequest.KeepAlive = true;
_webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
_webRequest.Referer = this.Url + "viewforum.php?f=" + this.AppsId;
string postData =
"do=postthread&f=" + this.AppsId +
"&wysiwyg=0&subject=" + subject +
"&message=" + message +
"&securitytoken=" + securityToken +
"&recaptcha_challenge_field=" + recaptchaChallenge +
"&recaptcha_response_field=" + recaptchaImageCode;
byte[] buffer = Encoding.UTF8.GetBytes(postData);
_webRequest.ContentLength = buffer.Length;
Stream dataStream = _webRequest.GetRequestStream();
dataStream.Write(buffer, 0, buffer.Length);
dataStream.Close();
try
{
_webRequest.GetResponse();
}
catch (WebException webException)
{
MessageBox.Show("Wystąpił błąd serwera: " + webException.Response);
}
}