Sixem

.NET Antigate Local Captcha

Mar 7th, 2013
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.49 KB | None | 0 0
  1. 'Written by Sixem
  2. Public Captcha_ID As String = Nothing
  3.     Public Function Send_Captcha(ByVal Key As String, ByVal Captcha_Path As String)
  4.         Captcha_ID = Nothing
  5.         Dim Image_ As Image = Image.FromFile(Captcha_Path)
  6.         'Add System.Web as reference
  7.         Dim Base64 As String = System.Web.HttpUtility.UrlEncode(ImageToBase64String(Image_, ImageFormat.Png))
  8.         Dim Push As String = Post_Data(String.Format("method=base64&key={0}&body={1}", Key, Base64), "http://antigate.com/in.php")
  9.         Dim CID As String = Push.Split("|").GetValue(1)
  10.         Captcha_ID = CID
  11.         Return CID
  12.     End Function
  13.     Public Function Captcha_Status(ByVal Key As String, ByVal CID As String)
  14.         Dim request As HttpWebRequest = DirectCast(WebRequest.Create(String.Format("http://antigate.com/res.php?key={0}&action=get&id={1}", Key, CID)), HttpWebRequest)
  15.         Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
  16.         Dim reader As New StreamReader(response.GetResponseStream())
  17.         Return reader.ReadToEnd
  18.     End Function
  19.     Public Function Post_Data(ByVal Post As String, ByVal URL As String)
  20.         Dim postData As String = Post
  21.         Dim encoding As New UTF8Encoding
  22.         Dim byteData As Byte() = encoding.GetBytes(postData)
  23.         Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create(URL), HttpWebRequest)
  24.         postReq.Method = "POST"
  25.         postReq.KeepAlive = True
  26.         postReq.ContentType = "application/x-www-form-urlencoded"
  27.         postReq.Referer = URL
  28.         postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
  29.         postReq.ContentLength = byteData.Length
  30.         Dim postreqstream As Stream = postReq.GetRequestStream()
  31.         postreqstream.Write(byteData, 0, byteData.Length)
  32.         postreqstream.Close()
  33.         Dim postresponse As HttpWebResponse
  34.         postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
  35.         Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
  36.         Return postreqreader.ReadToEnd
  37.     End Function
  38.     Public Shared Function ImageToBase64String(ByVal image As Image, ByVal imageFormat As Imaging.ImageFormat)
  39.         Using memStream As New MemoryStream
  40.             image.Save(memStream, imageFormat)
  41.             Dim result As String = Convert.ToBase64String(memStream.ToArray())
  42.             memStream.Close()
  43.             Return result
  44.         End Using
  45.     End Function
Advertisement
Add Comment
Please, Sign In to add comment