Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB6 Download Web Page Source

Tags:

webclient

vb6

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.

like image 678
Ben Avatar asked Jul 17 '10 06:07

Ben


2 Answers

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
like image 190
variant Avatar answered Sep 17 '22 19:09

variant


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.

like image 28
MarkJ Avatar answered Sep 17 '22 19:09

MarkJ