728x90

http://msdn.microsoft.com/en-us/library/aa384106(VS.85).aspx
Status : http://msdn.microsoft.com/en-us/library/aa383887(VS.85).aspx

Public WithEvents WinHttp As WinHttpRequest
Dim DownSize as Long

Private Sub WinHttp_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
'Start
DownSize = CLng(WinHttp.GetResponseHeader("Content-Length"))
If Not Dir(App.Path & "\" & App.EXEName & "-Old.exe") = vbNullString Then
  Kill App.Path & "\" & App.EXEName & "-Old.exe"
End If
Name App.Path & "\" & App.EXEName & ".exe" As App.Path & "\" & App.EXEName & "-Old.exe"
Open App.Path & "\" & App.EXEName & ".exe" For Binary As #1
End Sub

Private Sub WinHttp_OnResponseDataAvailable(Data() As Byte)
If DownSize > 0& Then
  Put #1, , Data()
End If
DoEvents
End Sub

Private Sub WinHttp_OnError(ByVal ErrorNumber As Long, ByVal ErrorDescription As String)
'Err
End Sub

Private Sub WinHttp_OnResponseFinished()
'End
Close #1
End Sub

파일 다운로드 예를 이벤트에 첨가 해두었습니다.
WinHttp COM 객체는 대용량 파일 다운로드에는 적합하지 못합니다.
제공되는 관련 API 를 이용하세요.

'적절한 곳에 넣어줍니다.
'Set WinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
Set WinHttp = New WinHttpRequest

WinHttp.Open "GET", "http://주소", True
WinHttp.Send "PARAM=1000"
WinHttp.WaitForResponse //완료까지 기다림
msgbox WinHttp.ResponseText
msgbox WinHttp.ResponseBody

728x90

'프로그래밍 > asp' 카테고리의 다른 글

SMTP, POP3로 메일 서버 구축하기  (0) 2011.09.16
windows 2003 ftp 설정  (0) 2011.09.05
ASP에서 UTF-8로 저장하기  (0) 2011.08.03
ASP에서 CSV 파일 생성하기  (0) 2011.08.03
ON Error Resume Next  (0) 2011.06.24

+ Recent posts