Using WebRequest and captcha's - Stuck on this Recaptcha - "Your Answer was correct."

simpleonline1234

Junior Member
Joined
Jan 26, 2010
Messages
170
Reaction score
13
I have my app setup to solve captcha's manually using webrequest.

With Re-captcha is something that I have to request myself from the server.

Enter the noscript version of the recaptcha code and it directs me to the re-captcha website.

I solve the code they give me there and it gives me the answer below.

If I try to paste that code into the response I get a bad string error.

I tested it on a webbrowser first but without a browser to see what's going on in my POST of the request I'm in the dark. The HTML of the code given back is just the same as the original so I'm assuming that it's failing on the POST as well.

My question is what the hell do we do with that long string they give me to use?

thanks

xkuikp.jpg
 

Attachments

  • xkuikp.jpg
    xkuikp.jpg
    10.3 KB · Views: 204
Hi.I couldn't reply this thread with "link" because of my low post count so I send it to pastebin :)
Paste id : 0JPBE6zp
 
Last edited:
Hey Thanks Piotr...looks good but it looks like your missing some chunks of code in there. There is no resposne defined, etc. I will tinker with the code tonight to see if I can piece together the missing info but this gives me a great head start...also I dont want to use a decatpcha service but to enter the captcha's for now.

I'm a VB.NET man so I converted it over but I wanted to post your code here since you went through all teh trouble of putting it onto another site. thanks again.

Code:
[SIZE=2][SIZE=2][COLOR=#ffffff]    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '1 - Get to website
        '2 - GET to recaptcha :[/COLOR]
[COLOR=#ffffff]
        Dim webRequest1 As HttpWebRequest = DirectCast(WebRequest.Create("[/COLOR][URL="http://www.google.com/recaptcha/api/challenge?k=XXXXXXXX"][COLOR=#ffffff]http://www.google.com/recaptcha/api/challenge?k=XXXXXXXX[/COLOR][/URL][COLOR=#ffffff]"), HttpWebRequest)[/COLOR]
[COLOR=#ffffff]        '3 - 2 returns some text and u have to use .Substring to get the challenge name from it .
        'My code:[/COLOR]
[COLOR=#ffffff]        Dim responseReader As New StreamReader(response.GetResponseStream())
        Dim sResponseHTML As String = responseReader.ReadToEnd()
        Dim a As Integer = sResponseHTML.IndexOf("challenge : '") + 13
        Dim x As String = sResponseHTML.Substring(a)
        Dim b As Integer = x.IndexOf("'")
        Dim chalname As String = x.Substring(0, b)[/COLOR]
[COLOR=#ffffff]        ' now u got the challenge name[/COLOR]
[COLOR=#ffffff]        chalname = chalname.Replace(Environment.NewLine, "")[/COLOR]
[COLOR=#ffffff]        Dim cpadres As String = "http: //www .google.com/recaptcha/api/image?c=" & chalname[/COLOR]
[COLOR=#ffffff]        ' cpadres is url when u can see captcha img 
        'U have to submit the cpadres to captchatrader,decaptcher etc and u will get solved captcha[/COLOR]
[COLOR=#ffffff]
        'postData = "nickLogin=" & login & " &passLogin=" & psswd & "&recaptcha_challenge_field=" & cpchallenge & "&recaptcha_response_field=" & cpsoled.Replace(" ", "+") & "&x=64&y=9"[/COLOR]
[COLOR=#ffffff]    End Sub[/COLOR]
[/SIZE][/SIZE]
 
U have to add

  1. Imports System.Net
  2. Imports System.IO

And the code :
pastebin : 3MCej02M

Best wishes :)


Some tip :
If u want to rewrite the captcha manually I suggest making another thread and pause it with
autoevent.waitone()
It is great solution ;]
 
Last edited:
Figured it out. Well half way. From me on my previous issues I can't let things go so I stripped my code down yet again and now rebuild smarter everything runs under a single button. The only interaction on the user so far is to enter the URL of the website they will to grap the captcha from.

I am going to work on building on how to use the POST method to send back to the server to create the account and be done with it.

Been going nutz over this project for about 3 months going back and forth between webbrowers an webrequest. Browsers suck with speed so I never really gave up on the webrequest.

With out further a due if anyone is looking to integrete using recaptcha in their program for the users to solve all that is needed is a 1 Picturebox, 2 Textboxes (1 named CaptchaRepo, 2 named WebsiteURL.text.

The code for the first button is as follows:

Code:
        Dim request As HttpWebRequest = HttpWebRequest.Create(WebsiteURL.Text)

        Dim response As HttpWebResponse
        response = CType(request.GetResponse, HttpWebResponse)
        Dim webstream As Stream = response.GetResponseStream
        Dim streamreader As New StreamReader(webstream, Encoding.UTF8)

        Dim html As String = streamreader.ReadToEnd

        'Now we have the source of the page lets parse and get the challenge url

        Dim web As IHTMLDocument2 = New HTMLDocumentClass()
        web.write(html)
        web.close()

        Dim allElements As IHTMLElementCollection = web.body.all
        Dim allScript As IHTMLElementCollection = allElements.tags("script")
        Dim element As IHTMLElement

        Dim challengeUrl As String = ""

        Dim tagName As String = ""
        For Each element In allScript
            tagName = element.getAttribute("src")
            If (Not tagName = Nothing) Then
                If (tagName.Contains("http://api.recaptcha.net/")) Then
                    challengeUrl = tagName
                    Exit For
                End If
            End If
        Next

        'Now we have the challenge url in challengeUrl variable, so lets "GET" it

        Dim request1 As HttpWebRequest = HttpWebRequest.Create(challengeUrl)

        Dim response1 As HttpWebResponse
        response1 = CType(request1.GetResponse, HttpWebResponse)
        Dim webstream1 As Stream = response1.GetResponseStream
        Dim streamreader1 As New StreamReader(webstream1, Encoding.UTF8)

        Dim temp As String = streamreader1.ReadToEnd

        'Now parse the index or whatever of that image, it is the thing that we are looking after

        Dim startPos As Integer = temp.IndexOf("challenge : '")
        startPos += 13
        temp = temp.Substring(startPos)
        Dim endPos As Integer = temp.IndexOf("'")

        temp = (temp.Substring(0, endPos))

        'Now the temp variabloe contains the key for the image.. You can download the image from

        PictureBox1.Load("http://www.google.com/recaptcha/api/image?c=" & temp)
    End Sub


Imports are

Imports System.IO
Imports System.Net
Imports mshtml
Imports System.Text
 
Back
Top