【WSH】Winhttpでhttpリクエストを行う(Text)

このエントリーをはてなブックマークに追加
Bookmark this on Livedoor Clip

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


Option Explicit

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

  HTTPDownload "http://google.co.jp/index.html" , "c:\text.txt"
Sub HTTPDownload(ByVal STR_URL, ByVal STR_Path )
    Dim OBJ_File
    Dim OBJ_FSO
    Dim OBJ_HTTP

    Set OBJ_FSO  = CreateObject("Scripting.FileSystemObject")
    Set OBJ_File = OBJ_FSO.OpenTextFile(STR_Path, OpenFileForWriting, True)
    Set OBJ_HTTP = CreateObject("WinHttp.WinHttpRequest.5.1")

    OBJ_HTTP.Open "GET", STR_URL, False
    OBJ_HTTP.Send

    OBJ_File.Write  OBJ_HTTP.ResponseText
    OBJ_File.Close( )
End Sub

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

VN:F [1.9.13_1145]
Rating: 9.0/10 (1 vote cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)
【WSH】Winhttpでhttpリクエストを行う(Text), 9.0 out of 10 based on 1 rating
This entry was posted in Windows, WSH.

コメントを残す

メールアドレスが公開されることはありません。

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

1 / 11