このエントリーをはてなブックマークに追加
[`livedoor` not found]

Winhttpでhttpリクエストを行い、Cドライブ直下に”test.gif”というファイルにリクエスト結果を保存する例です。

[vb]

Option Explicit

  Const OpenFileForReading   = 1
  Const OpenFileForWriting   = 2
  Const OpenFileForAppending = 8

  Const adTypeBinary = 1 ‘Binary
  Const adTypeText   = 2 ‘Text

  Const adSaveCreateNotExist  = 1
  Const adSaveCreateOverWrite = 2
  HTTPDownload “http://dragon-ark.com/wp-content/uploads/2008/12/20081231_1-300×166.gif” , “c:\test.gif”

 Sub HTTPDownload(ByVal STR_URL, ByVal STR_Path )
    Dim OBJ_ADO
    Dim OBJ_HTTP
    Dim STR_Temp

    Set OBJ_ADO  = CreateObject(“ADODB.Stream”)

    OBJ_ADO.Type = adTypeBinary
    OBJ_ADO.Open
    OBJ_ADO.Position = 0

    Set OBJ_HTTP = CreateObject(“WinHttp.WinHttpRequest.5.1”)

    OBJ_HTTP.Open “GET”, STR_URL, False
    OBJ_HTTP.Send

    STR_Temp = OBJ_HTTP.ResponseBody
    OBJ_ADO.Write STR_Temp
    OBJ_ADO.SaveToFile STR_Path, adSaveCreateNotExist
    OBJ_ADO.Close
End Sub
[/vb]

Scriptのダウンロードは こちら です。

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

Leave a Reply