views:

50

answers:

4

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.

+1  A: 

You have taken me back years. There is a useful Windows API call. Here is a url to point you in the right direction: http://allapi.mentalis.org/apilist/URLDownloadToFile.shtml

Carnotaurus
A: 

You can use the URLDownloadToFile function and then read the downloaded file into a string or textbox.

Example Code: http://vbnet.mvps.org/index.html?code/internet/urldownloadtofilenocache.htm

Adam Dempsey
+1  A: 

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.

MarkJ
A: 

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
variant