1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to Integrate Deathbycaptcha or decaptcher into VB.net?

Discussion in 'Visual Basic .NET' started by shaggy93, Jul 21, 2012.

  1. shaggy93

    shaggy93 Jr. VIP Jr. VIP Premium Member

    Joined:
    Dec 23, 2010
    Messages:
    1,027
    Likes Received:
    449
    Location:
    0.0.0.0
    Hello

    Wanted to ask that how you can integrate deathbycaptcha or decaptcher into vb.net,

    If somebody can help me out would really appreciate that and will give some templates too later on..

    Thanks
     
  2. webblackart

    webblackart Registered Member

    Joined:
    May 13, 2009
    Messages:
    60
    Likes Received:
    9
    all you need to do is implement their api, whats your issue with that?
     
  3. shaggy93

    shaggy93 Jr. VIP Jr. VIP Premium Member

    Joined:
    Dec 23, 2010
    Messages:
    1,027
    Likes Received:
    449
    Location:
    0.0.0.0
    I've been getting the problem while debugging it. It is giving some sort of errors... If you have got the source code for that , can you give it to me.
     
  4. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,881
    Likes Received:
    1,932
    Code:
    Imports System
    Imports System.Text
    Imports System.IO
    Imports System.Net
    
    Class Decaptcher
    
        Private username As String = My.Settings.DecaptcherUser
        Private password As String = My.Settings.DecaptcherPass
    
        Private resultCode As String = ""
        Private majorId As String = ""
        Private minorId As String = ""
        Private type As String = ""
        Private timeout As String = ""
    
        Public Function PostCaptcha(ByVal FilePath As String) As String
            Dim captcha As System.Drawing.Image
            Dim fs As New System.IO.FileStream(FilePath, System.IO.FileMode.Open)
            captcha = Image.FromStream(fs)
    
            Dim captchaResponse As String = ""
            Dim boundary As String = "myBoundary"
            Dim builder As New StringBuilder()
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""function""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append("picture2")
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""username""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append(username)
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""password""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append(password)
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""pict_to""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append("0")
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""pict_type""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append("0")
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""pict""; filename=captcha.jpg")
            builder.Append(vbCr & vbLf)
            builder.Append("Content-Type: image/jpeg")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
    
            Dim headerBytes As Byte() = Encoding.ASCII.GetBytes(builder.ToString())
    
            Dim ms As New MemoryStream()
            captcha.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
    
            Dim imageBytes As Byte() = ms.ToArray()
    
            Dim footerBytes As Byte() = Encoding.ASCII.GetBytes((vbCr & vbLf & "--") + boundary)
    
            Dim postBytes As Byte() = New Byte(headerBytes.Length + imageBytes.Length + (footerBytes.Length - 1)) {}
    
            Buffer.BlockCopy(headerBytes, 0, postBytes, 0, headerBytes.Length)
            Buffer.BlockCopy(imageBytes, 0, postBytes, headerBytes.Length, imageBytes.Length)
            Buffer.BlockCopy(footerBytes, 0, postBytes, headerBytes.Length + imageBytes.Length, footerBytes.Length)
    
            Try
                Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://poster.de-captcher.com/"), HttpWebRequest)
                req.Proxy = Nothing
                req.Method = "POST"
                req.ContentType = "multipart/form-data; boundary=" & boundary
                req.ContentLength = postBytes.Length
                req.ServicePoint.Expect100Continue = False
                ' req.Timeout = 30000
    
                Using reqStream As Stream = req.GetRequestStream()
                    reqStream.Write(postBytes, 0, postBytes.Length)
                End Using
                Using resp As WebResponse = req.GetResponse()
                    Using respStream As Stream = resp.GetResponseStream()
                        Using read As New StreamReader(respStream)
                            captchaResponse = read.ReadToEnd()
                        End Using
                    End Using
                End Using
    
                Dim respValues As String() = captchaResponse.Split("|"c)
                resultCode = respValues(0)
                majorId = respValues(1)
                minorId = respValues(2)
                type = respValues(3)
                timeout = respValues(4)
                captchaResponse = respValues(5)
                fs.Close()
                Return captchaResponse
            Catch ex As Exception
                If ex.Message.Contains("403") Then Throw New Exception("Incorrect DeCaptcher Login Details")
                If ex.Message.Contains("400") Then Throw New Exception("DeCaptcher Rejected The Captcha Image")
                If ex.Message.Contains("500") Then Throw New Exception("DeCaptcher Server Error Occured")
                If ex.Message.Contains("503") Then Throw New Exception("DeCaptcher Service Is Temporarily Unavailable")
                fs.Close()
                Return captchaResponse
            End Try
            fs.Close()
        End Function
    
        Public Sub BadCaptcha()
            Dim boundary As String = "myBoundary"
    
            Dim builder As New StringBuilder()
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""function""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append("picture_bad2")
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""username""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append(username)
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""password""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append(password)
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""major_id""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append(majorId)
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""minor_id""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append(minorId)
            builder.Append(vbCr & vbLf)
    
            builder.Append("--" & boundary & vbCr & vbLf & "Content-Disposition: form-data; name=")
            builder.Append("""submit""")
            builder.Append(vbCr & vbLf & vbCr & vbLf)
            builder.Append("Send")
            builder.Append(vbCr & vbLf)
            builder.Append("--" & boundary)
    
            Dim postString As String = builder.ToString()
    
            Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://poster.de-captcher.com/"), HttpWebRequest)
            req.Proxy = Nothing
            req.Method = "POST"
            req.ContentType = "multipart/form-data; boundary=" & boundary
            Using reqStream As Stream = req.GetRequestStream()
                reqStream.Write(Encoding.ASCII.GetBytes(postString), 0, postString.Length)
            End Using
            Using resp As WebResponse = req.GetResponse()
                Using respStream As Stream = resp.GetResponseStream()
                    Using read As New StreamReader(respStream)
                        Dim result As String = read.ReadToEnd()
                    End Using
                End Using
            End Using
        End Sub
    
    End Class
    
    ^^ Not the official one, add DecaptcherUser & DecaptcherPass to the project Settings or change to hard code these details.
     
    • Thanks Thanks x 2
  5. christoss1959

    christoss1959 Senior Member

    Joined:
    Nov 25, 2010
    Messages:
    894
    Likes Received:
    1,150
    Home Page:
    If you tell us which site you are interested in we could be more helpful in assisting you