Is there a way in VB6 to download a web pages source to a string or Textbox? For example in VB.Net the WebClient class allows you to do so using .DownloadString("google.com"), how can I do the same in vb6?
Note: I would like to avoid using a WebBrowser.
I don't know much about VB6, but in VBA...
Dim objHttp As Object, strURL as string, strText as string
Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
strURL = "http://www.yoursite.com/"
objHttp.Open "GET", strURL, False
objHttp.setRequestHeader "User-Agent", _
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHttp.Send ("")
strText = objHttp.responseText
Set objHttp = Nothing
There is a little-known way to do this with native VB6, using the AsyncRead method of UserControl and UserDocument objects - no need for API calls. You can even do it asynchronously if you wish.
Here's an excellent explanation and VB6 code for multiple simultaneous downloads, from the renowned VB6 guru Karl Peterson.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With