943,164 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 4588
  • VB.NET RSS
Dec 29th, 2009
0

Uploading Image With Decaptcher.com Using API

Expand Post »
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:
VB.NET Syntax (Toggle Plain Text)
  1. 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:
VB.NET Syntax (Toggle Plain Text)
  1. 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.

VB.NET Syntax (Toggle Plain Text)
  1. Imports System.Net
  2. Imports System.Text
  3. Imports System.IO
  4.  
  5. Public Class DecaptcherAPI
  6. Private Uri As String = "http://decaptcher.com/poster/"
  7.  
  8. Private username As String = "SNIP"
  9. Private password As String = "SNIP"
  10.  
  11. Public Sub New()
  12. End Sub
  13.  
  14. Public Sub New(ByVal _username As String, ByVal _password As String)
  15. username = _username
  16. password = _password
  17. End Sub
  18.  
  19. Public Function GetCaptchaSolved(ByVal FileUrl As String) As DecaptcherResult
  20. Dim request As HttpWebRequest = CType(WebRequest.Create(FileUrl), HttpWebRequest)
  21.  
  22. request.Method = "GET"
  23.  
  24. Dim response As HttpWebResponse = CType(request.GetResponse, HttpWebResponse)
  25. Dim requestStream As Stream = response.GetResponseStream
  26.  
  27. Dim streamLength As Integer = Convert.ToInt32(response.ContentLength)
  28. Dim fileData As Byte() = New Byte(Convert.ToInt32(streamLength)) {}
  29. requestStream.Read(fileData, 0, streamLength)
  30. requestStream.Close()
  31. Return GetCaptchaSolved(fileData)
  32.  
  33. Return GetCaptchaSolved(fileData)
  34. End Function
  35.  
  36.  
  37. Public Function GetCaptchaSolved(ByVal File As Byte()) As DecaptcherResult
  38. Dim request As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)
  39.  
  40. request.Method = "POST"
  41. request.KeepAlive = True
  42.  
  43. Dim boundary As String = "-------------------------" + DateTime.Now.Ticks.ToString("x")
  44. Dim header As String = vbCrLf & "--" + boundary + vbCrLf
  45. Dim footer As String = vbCrLf & "--" + boundary + vbCrLf
  46.  
  47. request.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)
  48.  
  49. Dim contents As StringBuilder = New StringBuilder()
  50. contents.Append(vbCrLf)
  51.  
  52. contents.Append(header)
  53. contents.Append("Content-Disposition: form-data; name=""function""" & vbCrLf)
  54. contents.Append(vbCrLf)
  55. contents.Append("picture2")
  56.  
  57. contents.Append(header)
  58. contents.Append("Content-Disposition: form-data; name=""username""" & vbCrLf)
  59. contents.Append(vbCrLf)
  60. contents.Append(username)
  61.  
  62. contents.Append(header)
  63. contents.Append("Content-Disposition: form-data; name=""password""" & vbCrLf)
  64. contents.Append(vbCrLf)
  65. contents.Append(password)
  66.  
  67. contents.Append(header)
  68. contents.Append("Content-Disposition: form-data; name=""pict_to""" & vbCrLf)
  69. contents.Append(vbCrLf)
  70. contents.Append("0")
  71.  
  72. contents.Append(header)
  73. contents.Append("Content-Disposition: form-data; name=""pict_type""" & vbCrLf)
  74. contents.Append(vbCrLf)
  75. contents.Append("0")
  76.  
  77. contents.Append(header)
  78. contents.Append("Content-Disposition: form-data; name=""pict""; filename=""Untitled.jpg""" + vbCrLf)
  79. contents.Append("Content-Type: image/jpeg" + vbCrLf)
  80. contents.Append(vbCrLf)
  81.  
  82. Dim BodyBytes As Byte() = Encoding.UTF8.GetBytes(contents.ToString())
  83. Dim footerBytes As Byte() = Encoding.UTF8.GetBytes(footer)
  84.  
  85. request.ContentLength = BodyBytes.Length + File.Length + footerBytes.Length
  86.  
  87. Dim requestStream As Stream = request.GetRequestStream()
  88. requestStream.Write(BodyBytes, 0, BodyBytes.Length)
  89. requestStream.Write(File, 0, File.Length)
  90. requestStream.Write(footerBytes, 0, footerBytes.Length)
  91. requestStream.Flush()
  92. requestStream.Close()
  93.  
  94.  
  95. Dim ret As String = New StreamReader(request.GetResponse.GetResponseStream).ReadToEnd
  96.  
  97. Try
  98.  
  99. Return New DecaptcherResult(ret.Split("|")(0), ret.Split("|")(1), ret.Split("|")(2), ret.Split("|")(3), _
  100. ret.Split("|")(4), ret.Split("|")(5))
  101. Catch ex As Exception
  102. End Try
  103.  
  104. End Function
  105.  
  106. Public Function ClaimBad(ByVal dr As DecaptcherResult) As DecaptcherResult
  107. Dim request As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)
  108.  
  109. request.Method = "POST"
  110. request.KeepAlive = True
  111.  
  112. Dim boundary As String = "-------------------------" + DateTime.Now.Ticks.ToString("x")
  113. Dim header As String = vbCrLf & "--" + boundary + vbCrLf
  114. Dim footer As String = vbCrLf & "--" + boundary + vbCrLf
  115.  
  116. request.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)
  117.  
  118. Dim contents As StringBuilder = New StringBuilder()
  119. contents.Append(vbCrLf)
  120.  
  121. contents.Append(header)
  122. contents.Append("Content-Disposition: form-data; name=""function""" & vbCrLf)
  123. contents.Append(vbCrLf)
  124. contents.Append("picture_bad2")
  125.  
  126. contents.Append(header)
  127. contents.Append("Content-Disposition: form-data; name=""username""" & vbCrLf)
  128. contents.Append(vbCrLf)
  129. contents.Append(username)
  130.  
  131. contents.Append(header)
  132. contents.Append("Content-Disposition: form-data; name=""password""" & vbCrLf)
  133. contents.Append(vbCrLf)
  134. contents.Append(password)
  135.  
  136. contents.Append(header)
  137. contents.Append("Content-Disposition: form-data; name=""major_id""" & vbCrLf)
  138. contents.Append(vbCrLf)
  139. contents.Append(dr.MajorID)
  140.  
  141. contents.Append(header)
  142. contents.Append("Content-Disposition: form-data; name=""minor_id""" & vbCrLf)
  143. contents.Append(vbCrLf)
  144. contents.Append(dr.MinorID)
  145.  
  146. Dim BodyBytes As Byte() = Encoding.UTF8.GetBytes(contents.ToString())
  147. Dim footerBytes As Byte() = Encoding.UTF8.GetBytes(footer)
  148.  
  149. request.ContentLength = BodyBytes.Length + footerBytes.Length
  150.  
  151. Dim requestStream As Stream = request.GetRequestStream()
  152. requestStream.Write(BodyBytes, 0, BodyBytes.Length)
  153. requestStream.Write(footerBytes, 0, footerBytes.Length)
  154. requestStream.Flush()
  155. requestStream.Close()
  156.  
  157. Dim ret As String = New StreamReader(request.GetResponse.GetResponseStream).ReadToEnd
  158.  
  159. Return New DecaptcherResult(ret.Split("|")(0), ret.Split("|")(1), ret.Split("|")(2), ret.Split("|")(3), _
  160. ret.Split("|")(4), ret.Split("|")(5))
  161.  
  162. End Function
  163.  
  164. Public Function GetBalance() As String
  165. Dim request As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)
  166.  
  167. request.Method = "POST"
  168. request.KeepAlive = True
  169.  
  170. Dim boundary As String = "-------------------------" + DateTime.Now.Ticks.ToString("x")
  171. Dim header As String = vbCrLf & "--" + boundary + vbCrLf
  172. Dim footer As String = vbCrLf & "--" + boundary + vbCrLf
  173.  
  174. request.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)
  175.  
  176. Dim contents As StringBuilder = New StringBuilder()
  177. contents.Append(vbCrLf)
  178.  
  179. contents.Append(header)
  180. contents.Append("Content-Disposition: form-data; name=""function""" & vbCrLf)
  181. contents.Append(vbCrLf)
  182. contents.Append("balance")
  183.  
  184. contents.Append(header)
  185. contents.Append("Content-Disposition: form-data; name=""username""" & vbCrLf)
  186. contents.Append(vbCrLf)
  187. contents.Append(username)
  188.  
  189. contents.Append(header)
  190. contents.Append("Content-Disposition: form-data; name=""password""" & vbCrLf)
  191. contents.Append(vbCrLf)
  192. contents.Append(password)
  193.  
  194. Dim BodyBytes As Byte() = Encoding.UTF8.GetBytes(contents.ToString())
  195. Dim footerBytes As Byte() = Encoding.UTF8.GetBytes(footer)
  196.  
  197. request.ContentLength = BodyBytes.Length + footerBytes.Length
  198.  
  199. Dim requestStream As Stream = request.GetRequestStream()
  200. requestStream.Write(BodyBytes, 0, BodyBytes.Length)
  201. requestStream.Write(footerBytes, 0, footerBytes.Length)
  202. requestStream.Flush()
  203. requestStream.Close()
  204.  
  205. Dim ret As String = New StreamReader(request.GetResponse.GetResponseStream).ReadToEnd
  206.  
  207. Return ret
  208. End Function
  209.  
  210. Protected Overrides Sub Finalize()
  211. MyBase.Finalize()
  212. End Sub
  213. End Class
  214.  
  215. Public Class DecaptcherResult
  216.  
  217. Public Sub New()
  218. End Sub
  219.  
  220. Public Sub New(ByVal resultCode As String, ByVal majorID As String, ByVal minorID As String, ByVal type As String, _
  221. ByVal timeout As String, ByVal text As String)
  222. Me._ResultCode = resultCode
  223. Me._MajorID = majorID
  224. Me._MinorID = minorID
  225. Me._Type = type
  226. Me._Timeout = timeout
  227. Me._Text = text
  228. End Sub
  229.  
  230. Public Property ResultCode() As String
  231. Get
  232. Return _ResultCode
  233. End Get
  234. Set(ByVal value As String)
  235. _ResultCode = value
  236. End Set
  237. End Property
  238.  
  239. Public Property MajorID() As String
  240. Get
  241. Return _MajorID
  242. End Get
  243. Set(ByVal value As String)
  244. _MajorID = value
  245. End Set
  246. End Property
  247.  
  248. Public Property MinorID() As String
  249. Get
  250. Return _MinorID
  251. End Get
  252. Set(ByVal value As String)
  253. _MinorID = value
  254. End Set
  255. End Property
  256.  
  257. Public Property Type() As String
  258. Get
  259. Return _Type
  260. End Get
  261. Set(ByVal value As String)
  262. _Type = value
  263. End Set
  264. End Property
  265.  
  266. Public Property Timeout() As String
  267. Get
  268. Return _Timeout
  269. End Get
  270. Set(ByVal value As String)
  271. _Timeout = value
  272. End Set
  273. End Property
  274.  
  275. Public Property Text() As String
  276. Get
  277. Return _Text
  278. End Get
  279. Set(ByVal value As String)
  280. _Text = value
  281. End Set
  282. End Property
  283.  
  284.  
  285. Private _ResultCode As String
  286. Private _MajorID As String
  287. Private _MinorID As String
  288. Private _Type As String
  289. Private _Timeout As String
  290. Private _Text As String
  291. End Class
Last edited by happygeek; Dec 29th, 2009 at 5:42 pm. Reason: user/pass deleted
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ludamizleeto is offline Offline
5 posts
since Dec 2009
Dec 29th, 2009
0
Re: Uploading Image With Decaptcher.com Using API
You do realize you posted your username and password in the code, right?
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Dec 29th, 2009
0

no

Click to Expand / Collapse  Quote originally posted by sknake ...
You do realize you posted your username and password in the code, right?
Its just a made up one.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ludamizleeto is offline Offline
5 posts
since Dec 2009
Dec 30th, 2009
0

re: decaptcha

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>>
Last edited by Nick Evan; Dec 30th, 2009 at 3:30 pm. Reason: snipped mail
Reputation Points: 10
Solved Threads: 5
Light Poster
marketingmaniac is offline Offline
38 posts
since Dec 2009
Dec 30th, 2009
0

Decaptcher

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

VB.NET Syntax (Toggle Plain Text)
  1. Public Class Form1
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. Dim i As Object
  5.  
  6. Dim ret As Short
  7. Dim id As Short
  8. Dim host As String
  9. Dim name As String
  10. Dim password As String
  11. Dim pic() As Byte
  12. Dim pic_name As String
  13. Dim fnum As Short
  14. Dim str_out(255) As Byte
  15. Dim file_length As Integer
  16. Dim captcha As String
  17. Dim balance As Single
  18.  
  19.  
  20. Dim p_pict_to(1) As Integer
  21. Dim p_pict_type(1) As Integer
  22. Dim major_id(1) As Integer
  23. Dim minor_id(1) As Integer
  24. Dim size_str_out As Integer
  25.  
  26. ' Connection information Specify YOUR HOST PORT LOGIN PASSWORD
  27. host = CStr("THE IP THEY GAVE YOU")
  28. name = CStr("YOUR USERNAME")
  29. password = CStr("YOUR PASSWORD")
  30. pic_name = "C:\pic.jpg"
  31.  
  32.  
  33.  
  34. size_str_out = 255
  35.  
  36. file_length = FileLen(pic_name)
  37.  
  38. fnum = FreeFile()
  39. '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"'
  40. ReDim pic(file_length)
  41.  
  42. FileOpen(fnum, pic_name, OpenMode.Binary)
  43. '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"'
  44. 'FileGet(fnum, pic, 1)
  45. FileClose(fnum)
  46.  
  47.  
  48.  
  49. ret = DecaptcherInit()
  50.  
  51. If ret <> 0 Then
  52. Exit Sub
  53. End If
  54.  
  55. id = CCprotoInit()
  56.  
  57. If id < 0 Then
  58. Exit Sub
  59. End If
  60. 'Dim yourport As Long
  61. ret = CCprotoLogin(id, host, THE PORT THEY GAVE YOU, name, Len(name), password, Len(password))
  62. '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"'
  63.  
  64. If ret <> 0 Then
  65. Exit Sub
  66. End If
  67.  
  68. ret = CCprotoBalance(id, balance)
  69.  
  70. 'ret = CCprotoPicture(id, pic(1), file_length, str_out(1))
  71. 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))
  72.  
  73.  
  74. If ret <> 0 Then
  75. Exit Sub
  76. End If
  77.  
  78. For i = 1 To 255
  79. '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"'
  80. If (str_out(i) = 0) Then
  81. Exit For
  82. End If
  83. '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"'
  84. captcha = captcha & Chr(str_out(i))
  85. Next
  86.  
  87. ' if the captcha was recognize incorrectly
  88. ' then call
  89. ' ret = CCprotoPictureBad(id)
  90.  
  91. MsgBox(captcha)
  92.  
  93. ret = CCprotoClose(id)
  94. ret = CCprotoDestroy(id)
  95. ret = DecaptcherDestroy()
  96.  
  97. End Sub
  98. End Class
Reputation Points: 10
Solved Threads: 5
Light Poster
marketingmaniac is offline Offline
38 posts
since Dec 2009
Jan 21st, 2010
0
Re: Uploading Image With Decaptcher.com Using API
VB.NET Syntax (Toggle Plain Text)
  1. host = CStr("THE IP THEY GAVE YOU") (where can i find this? in decapthcer.com?)
  2. name = CStr("YOUR USERNAME") ( in decaptcher.com?)
  3. password = CStr("YOUR PASSWORD") (in decaptcher.com?)
  4. pic_name = "C:\pic.jpg"
Reputation Points: 10
Solved Threads: 0
Light Poster
darcee is offline Offline
47 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Problem with the "Like Operator"
Next Thread in VB.NET Forum Timeline: Count how many vowels there are in a word or phrase





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC