VB6 Download Web Page Source

时光怂恿深爱的人放手 提交于 2019-12-10 13:54:39

问题


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:


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



回答2:


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.




回答3:


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



回答4:


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



来源:https://stackoverflow.com/questions/3270563/vb6-download-web-page-source

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!