Question

i have webbrowser control to open website I want to get captcha image that appears on this web page to show in pictureBox.....

<img src="/alpha/captcha.php?1393609547" width="150" height="25" title="Click for another image" alt="CAPTCHA" id="asc" />

An example of this

enter image description here

Thanks for your help

No correct solution

OTHER TIPS

First, I see that the image src URL is a relative URL. That means you need to make it an absolute by doing something like this:

Dim absoluteURL As String = "domain of captcha" & captchaURL

Then, you need to download the image into Bytes by doing something like this:

Dim PictureBytes As Byte()

' Convert String to a Uri
Dim address As New Uri(absoluteURL, UriKind.Absolute)

' Create the web request  
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(address), HttpWebRequest)

' Set type to GET  
request.Method = "GET"

Try
    ' Get response  
    Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)

    ' Get the response stream into a reader  
    Dim stream As Stream = response.GetResponseStream
    Dim reader New BinaryReader(stream)

    PictureBytes = reader.ReadBytes(stream.Length)
Finally
    If Not response Is Nothing Then response.Close()
End Try

Finally, you will need to convert the bytes to a bitmap and put that bitmap in a picture box

Dim Captcha As New Bitmap(new MemoryStream(PictureBytes));
pictureBox.Image = Captcha

 

If you encounter any problems, just comment on this post. If this code works, please consider marking this correct and up-voting. Please note, up-voting or marking an answer correct DOES NOT subtract reputation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top