开发者

VB6 Download Web Page Source

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?

Not开发者_运维问答e: 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.


You have taken me back years. There is a useful Windows API call for this purpose:

Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜