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