How to make Internet Explorer open Invisible in VB6?

Performance:

Shell ("C:\Program Files\Internet Explorer\iexplore.exe -embedding http://www.websiteurl.com")

It does not work as I need it, since I essentially need it to be able to redirect and request the user to download the file. Any ideas?

+3
source share
6 answers

Internet Explorer provides an accessible COM interface that you can use. If you really need to. I would recommend against this - its relatively slow, error prone, bulky and resource intensive.

What is more convenient to solve your problem is used WinHTTPRequest. In your project, refer to "Microsoft WinHTTP Services, Version 5.1," and then continue:

Dim HttpRequest As New WinHttp.WinHttpRequest
Dim TargetUrl As String
Dim TargetFile As String
Dim FileNum As Integer

TargetFile = "C:\foo.doc"

TargetUrl = "http://www.websiteurl.com"
HttpRequest.Open Method:="GET", Url:=TargetUrl, Async:=False
HttpRequest.Send

If HttpRequest.Status = 302 Then

  TargetUrl = HttpRequest.GetResponseHeader("Location")
  HttpRequest.Open Method:="GET", Url:=TargetUrl, Async:=False
  HttpRequest.Send

  If HttpRequest.Status = "200" Then

    FileNum = FreeFile
    Open TargetFile For Binary As #FileNum
    Put #FileNum, 1, HttpRequest.ResponseBody
    Close FileNum 

    Debug.Print "Successfully witten " & TargetFile
  Else
    Debug.Print "Download failed. Received HTTP status: " & HttpRequest.Status
  End If
Else
  Debug.Print "Expected Redirect. Received HTTP status: " & HttpRequest.Status
End If

"C:\foo.doc", , . , ("Content-Type" "Content-Disposition", , ).

+5

, .

+1
0

Internet Explorer ActiveX WebBrowser ( % systemroot%\system32\shlwapi.dll). , - .

.

0

It is best to create a separate download application using some .NET http object to download the file. I would recommend WebClient.

If you really need to stick with VB6, I'm sure you can use some basic socket work to directly download the file.

0
source

Another option, besides the URLDownloadToFile API request suggested by Glomek, is to use the AsyncRead built into VB6.

0
source

Source: https://habr.com/ru/post/1698712/


All Articles