トップ 履歴 一覧 カテゴリ ソース 検索 ヘルプ RSS ログイン

Source/VBS/HttpSend

INDEX

VBScriptでHTTPメソッドテスト

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Option Explicit
' ============================================================================ '
'  HTTPメソッドテスト (HttpSendTest.vbs)
' ============================================================================ '

' 送信するURL とID/PW
Const SEND_URL="https://example.com/TEST/test.txt"
Const USERNAME="username"
Const PASSWORD="password"

' HTTPメソッド HEAD/GET/POST/PUT/DELETE
Const METHOD="HEAD"

' 送信データ ※POST/PUT でのみ有効
Const SENDDATA="TEST DATA"


Dim xmlhttp
'Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")

' SSL証明書でエラーを検知した場合の動作(ServerXMLHTTP)
xmlhttp.setOption 2, 13056 ' 証明書のエラーを無視する

' プロキシサーバ(ServerXMLHTTP 6.0以上)
' 第一引数:プロキシ構成(0:デフォルト構成, 1:すべてのHTTPとHTTPSで直接接続, 2:プロキシサーバを指定)
' 第二引数:プロキシサーバ、第三引数:バイパスリスト
xmlhttp.setProxy 0, "127.0.0.1:8080", "localhost;127.0.0.1"
'xmlhttp.setProxyCredentials username, password ' プロキシ認証


' 接続
xmlhttp.Open METHOD, SEND_URL, False, USERNAME, PASSWORD
xmlhttp.Send SENDDATA

' 結果
WScript.Echo METHOD & " status: " & xmlhttp.status & " " & xmlhttp.statusText
WScript.Echo METHOD & " Headers:" & vbNewLine & xmlhttp.getAllResponseHeaders
WScript.Echo METHOD & " Response:" & vbNewLine & xmlhttp.responseText

WScript.Quit

' ============================================================================ '
' HTTP POST/PUT Send File

' 送信データファイル
Const SENDFILE=""

' ----------------
Const adTypeBinary = 1 ' 
Const adTypeText   = 2 ' 

Dim stream
Set stream = CreateObject("ADODB.Stream")

' 送信するファイルの読み込み
stream.Open
stream.Type = adTypeText
stream.Charset = "UTF-8"
stream.LoadFromFile LOADFILE
stream.Position = 0

If stream.Type = adTypeText Then
  WScript.Echo "FILE DATA:" & vbNewLine & stream.ReadText
  stream.Position = 0
End If

' 接続
xmlhttp.Open METHOD, SEND_URL, False, USERNAME, PASSWORD
xmlhttp.Send stream

' 結果
WScript.Echo METHOD & " status: " & xmlhttp.status & " " & xmlhttp.statusText

WScript.Quit
' ============================================================================ '
'   End Of File (HttpSendTest.vbs)                                             '
' ============================================================================ '

最終更新時間:2016年10月14日 18時03分13秒 指摘や意見などあればSandBoxのBBSへ。

HttpSendTest.vbs