1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Const scUserAgent = ""
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Sub Command1_Click()
Dim hOpen As Long, hFile As Long, sBuffer As String, hRet As Long
'Create a buffer for the file we're going to download
sBuffer = Space(20000)
'Create an internet connection
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
'Open the url
hFile = InternetOpenUrl(hOpen, "http://www.passiblog.com/404.txt", vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
'Lit le fichier > buffer
InternetReadFile hFile, sBuffer, Len(sBuffer), hRet
'clean up
InternetCloseHandle hFile
InternetCloseHandle hOpen
'-- recuperer la chaine lue
Contents = Trim(sBuffer)
Debug.Print Contents
End Sub |
Partager