I have always used the API for Vb.net from Decaptcher.com and have always sent the Captcha by sending an actual url to them as you see in the code below. Or maybe it uploaded the image anyway to them (I use the Webbrowser Control) I'll use for example this:

Code:

Dim dr As DecaptcherResult = DecaptAPI.GetCaptchaSolved(Me.WebBrowser1.Document.GetElementById("captcha_image").GetAttribute("src"))

But with the current project that I am working on right now I am having to take a screen shot of the captcha image, then save it to my harddrive.

I know that through your API Decaptcher allows us to upload the image from our harddrive but I just can't figure out how to use the code to do this. I have tried this but it doesn't work:

Code:

Dim dr As DecaptcherResult = DecaptAPI.GetCaptchaSolved("c:\1\Untitled.jpg")

Can anyone please tell me the proper code to send the image and get the response.

Thank you so much

BELOW THIS IS THE CLASS AS WELL WITH THIS.
THANK YOU SO SO MUCH TO WHO EVER WILL HELP ME WITH THIS, IT MEANS SO MUCH TO ME.

Imports System.Net
Imports System.Text
Imports System.IO

Public Class DecaptcherAPI
    Private Uri As String = "http://decaptcher.com/poster/"

    Private username As String = "SNIP"
    Private password As String = "SNIP"

    Public Sub New()
    End Sub

    Public Sub New(ByVal _username As String, ByVal _password As String)
        username = _username
        password = _password
    End Sub

    Public Function GetCaptchaSolved(ByVal FileUrl As String) As DecaptcherResult
        Dim request As HttpWebRequest = CType(WebRequest.Create(FileUrl), HttpWebRequest)

        request.Method = "GET"

        Dim response As HttpWebResponse = CType(request.GetResponse, HttpWebResponse)
        Dim requestStream As Stream = response.GetResponseStream

        Dim streamLength As Integer = Convert.ToInt32(response.ContentLength)
        Dim fileData As Byte() = New Byte(Convert.ToInt32(streamLength)) {}
        requestStream.Read(fileData, 0, streamLength)
        requestStream.Close()
        Return GetCaptchaSolved(fileData)

        Return GetCaptchaSolved(fileData)
    End Function


    Public Function GetCaptchaSolved(ByVal File As Byte()) As DecaptcherResult
        Dim request As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)

        request.Method = "POST"
        request.KeepAlive = True

        Dim boundary As String = "-------------------------" + DateTime.Now.Ticks.ToString("x")
        Dim header As String = vbCrLf & "--" + boundary + vbCrLf
        Dim footer As String = vbCrLf & "--" + boundary + vbCrLf

        request.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)

        Dim contents As StringBuilder = New StringBuilder()
        contents.Append(vbCrLf)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""function""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append("picture2")

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""username""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append(username)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""password""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append(password)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""pict_to""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append("0")

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""pict_type""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append("0")

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""pict""; filename=""Untitled.jpg""" + vbCrLf)
        contents.Append("Content-Type: image/jpeg" + vbCrLf)
        contents.Append(vbCrLf)

        Dim BodyBytes As Byte() = Encoding.UTF8.GetBytes(contents.ToString())
        Dim footerBytes As Byte() = Encoding.UTF8.GetBytes(footer)

        request.ContentLength = BodyBytes.Length + File.Length + footerBytes.Length

        Dim requestStream As Stream = request.GetRequestStream()
        requestStream.Write(BodyBytes, 0, BodyBytes.Length)
        requestStream.Write(File, 0, File.Length)
        requestStream.Write(footerBytes, 0, footerBytes.Length)
        requestStream.Flush()
        requestStream.Close()


        Dim ret As String = New StreamReader(request.GetResponse.GetResponseStream).ReadToEnd

        Try

            Return New DecaptcherResult(ret.Split("|")(0), ret.Split("|")(1), ret.Split("|")(2), ret.Split("|")(3), _
                                        ret.Split("|")(4), ret.Split("|")(5))
        Catch ex As Exception
        End Try

    End Function

    Public Function ClaimBad(ByVal dr As DecaptcherResult) As DecaptcherResult
        Dim request As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)

        request.Method = "POST"
        request.KeepAlive = True

        Dim boundary As String = "-------------------------" + DateTime.Now.Ticks.ToString("x")
        Dim header As String = vbCrLf & "--" + boundary + vbCrLf
        Dim footer As String = vbCrLf & "--" + boundary + vbCrLf

        request.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)

        Dim contents As StringBuilder = New StringBuilder()
        contents.Append(vbCrLf)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""function""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append("picture_bad2")

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""username""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append(username)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""password""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append(password)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""major_id""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append(dr.MajorID)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""minor_id""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append(dr.MinorID)

        Dim BodyBytes As Byte() = Encoding.UTF8.GetBytes(contents.ToString())
        Dim footerBytes As Byte() = Encoding.UTF8.GetBytes(footer)

        request.ContentLength = BodyBytes.Length + footerBytes.Length

        Dim requestStream As Stream = request.GetRequestStream()
        requestStream.Write(BodyBytes, 0, BodyBytes.Length)
        requestStream.Write(footerBytes, 0, footerBytes.Length)
        requestStream.Flush()
        requestStream.Close()

        Dim ret As String = New StreamReader(request.GetResponse.GetResponseStream).ReadToEnd

        Return New DecaptcherResult(ret.Split("|")(0), ret.Split("|")(1), ret.Split("|")(2), ret.Split("|")(3), _
                                    ret.Split("|")(4), ret.Split("|")(5))

    End Function

    Public Function GetBalance() As String
        Dim request As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)

        request.Method = "POST"
        request.KeepAlive = True

        Dim boundary As String = "-------------------------" + DateTime.Now.Ticks.ToString("x")
        Dim header As String = vbCrLf & "--" + boundary + vbCrLf
        Dim footer As String = vbCrLf & "--" + boundary + vbCrLf

        request.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)

        Dim contents As StringBuilder = New StringBuilder()
        contents.Append(vbCrLf)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""function""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append("balance")

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""username""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append(username)

        contents.Append(header)
        contents.Append("Content-Disposition: form-data; name=""password""" & vbCrLf)
        contents.Append(vbCrLf)
        contents.Append(password)

        Dim BodyBytes As Byte() = Encoding.UTF8.GetBytes(contents.ToString())
        Dim footerBytes As Byte() = Encoding.UTF8.GetBytes(footer)

        request.ContentLength = BodyBytes.Length + footerBytes.Length

        Dim requestStream As Stream = request.GetRequestStream()
        requestStream.Write(BodyBytes, 0, BodyBytes.Length)
        requestStream.Write(footerBytes, 0, footerBytes.Length)
        requestStream.Flush()
        requestStream.Close()

        Dim ret As String = New StreamReader(request.GetResponse.GetResponseStream).ReadToEnd

        Return ret
    End Function

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class

Public Class DecaptcherResult

    Public Sub New()
    End Sub

    Public Sub New(ByVal resultCode As String, ByVal majorID As String, ByVal minorID As String, ByVal type As String, _
                   ByVal timeout As String, ByVal text As String)
        Me._ResultCode = resultCode
        Me._MajorID = majorID
        Me._MinorID = minorID
        Me._Type = type
        Me._Timeout = timeout
        Me._Text = text
    End Sub

    Public Property ResultCode() As String
        Get
            Return _ResultCode
        End Get
        Set(ByVal value As String)
            _ResultCode = value
        End Set
    End Property

    Public Property MajorID() As String
        Get
            Return _MajorID
        End Get
        Set(ByVal value As String)
            _MajorID = value
        End Set
    End Property

    Public Property MinorID() As String
        Get
            Return _MinorID
        End Get
        Set(ByVal value As String)
            _MinorID = value
        End Set
    End Property

    Public Property Type() As String
        Get
            Return _Type
        End Get
        Set(ByVal value As String)
            _Type = value
        End Set
    End Property

    Public Property Timeout() As String
        Get
            Return _Timeout
        End Get
        Set(ByVal value As String)
            _Timeout = value
        End Set
    End Property

    Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property


    Private _ResultCode As String
    Private _MajorID As String
    Private _MinorID As String
    Private _Type As String
    Private _Timeout As String
    Private _Text As String
End Class

Recommended Answers

All 5 Replies

You do realize you posted your username and password in the code, right?

You do realize you posted your username and password in the code, right?

Its just a made up one.

i am also having a problem,,

the decapture.dll seems to be written in vb 2003 and im using the vb 2008,,

did you get it to compile in visual studio 2008? and if so ,, i cant seem to reference the decapture.dll in mine,, do you have a copy of one? and or are you using the dll at all?

mike
<<mail removed>>

this is the code to send it do them but you need a valid decaptcha dll in your refrence,, which i am looking for ,, and they are not helping with email,, lol

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Object

        Dim ret As Short
        Dim id As Short
        Dim host As String
        Dim name As String
        Dim password As String
        Dim pic() As Byte
        Dim pic_name As String
        Dim fnum As Short
        Dim str_out(255) As Byte
        Dim file_length As Integer
        Dim captcha As String
        Dim balance As Single


        Dim p_pict_to(1) As Integer
        Dim p_pict_type(1) As Integer
        Dim major_id(1) As Integer
        Dim minor_id(1) As Integer
        Dim size_str_out As Integer

        ' Connection information Specify YOUR HOST PORT LOGIN PASSWORD
        host = CStr("THE IP THEY GAVE YOU")
        name = CStr("YOUR USERNAME")
        password = CStr("YOUR PASSWORD")
        pic_name = "C:\pic.jpg"



        size_str_out = 255

        file_length = FileLen(pic_name)

        fnum = FreeFile()
        'UPGRADE_WARNING: Lower bound of array pic was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
        ReDim pic(file_length)

        FileOpen(fnum, pic_name, OpenMode.Binary)
        'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
        'FileGet(fnum, pic, 1)
        FileClose(fnum)



        ret = DecaptcherInit()

        If ret <> 0 Then
            Exit Sub
        End If

        id = CCprotoInit()

        If id < 0 Then
            Exit Sub
        End If
        'Dim yourport As Long
        ret = CCprotoLogin(id, host, THE PORT THEY GAVE YOU, name, Len(name), password, Len(password))
        'UPGRADE_ISSUE: The preceding line couldn't be parsed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="82EBB1AE-1FCB-4FEF-9E6C-8736A316F8A7"'

        If ret <> 0 Then
            Exit Sub
        End If

        ret = CCprotoBalance(id, balance)

        'ret = CCprotoPicture(id, pic(1), file_length, str_out(1))
        ret = CCprotoPicture2(id, pic(1), file_length, p_pict_to(1), p_pict_type(1), str_out(1), size_str_out, major_id(1), minor_id(1))


        If ret <> 0 Then
            Exit Sub
        End If

        For i = 1 To 255
            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            If (str_out(i) = 0) Then
                Exit For
            End If
            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            captcha = captcha & Chr(str_out(i))
        Next

        ' if the captcha was recognize incorrectly
        ' then call
        ' ret = CCprotoPictureBad(id)

        MsgBox(captcha)

        ret = CCprotoClose(id)
        ret = CCprotoDestroy(id)
        ret = DecaptcherDestroy()

    End Sub
End Class
host = CStr("THE IP THEY GAVE YOU") (where can i find this? in decapthcer.com?)
name = CStr("YOUR USERNAME") ( in decaptcher.com?)
password = CStr("YOUR PASSWORD") (in decaptcher.com?)
pic_name = "C:\pic.jpg"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.