Option Explicit

' thx to
' id:ardarim http://q.hatena.ne.jp/1171410367
' http://blog.goo.ne.jp/ghostwind/e/87b0af815fb2a7bc7ec9b6e4a781021f

Sub test()

If GetUrl("http://example.com/hogehoge.php", "c:\posttest.html") Then
'MsgBox "成功"
MsgBox "失敗"
End If

End Sub

Function GetUrl(ByVal url As String, ByVal filename As String) As Boolean

Dim i As Long, l As Long
Dim fn As Integer
Dim html As String
Dim b() As Byte

Dim WinHttp As New WinHttpRequest ' winhttp.dll
' Dim WinHttp As Object
' Set WinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

WinHttp.Open "POST", url, False
WinHttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WinHttp.Send "name=22&name2=33"

If WinHttp.Status < 200 And WinHttp.Status > 399 Then
GetUrl = False
Exit Function
End If

l = LenB(WinHttp.ResponseBody)
fn = FreeFile()
Open filename For Binary Access Write As #fn
html = WinHttp.ResponseBody
ReDim b(l)
For i = 1 To l
b(i - 1) = AscB(MidB(html, i, 1))
Next i
Put #fn, , b
Close #fn

GetUrl = True
On Error GoTo 0
Exit Function

If fn <> 0 Then Close #fn
GetUrl = False
On Error GoTo 0

End Function