Skip to content

Instantly share code, notes, and snippets.

@cabloo
Created March 21, 2016 18:03
Show Gist options
  • Save cabloo/387f1d6d8fe81752574d to your computer and use it in GitHub Desktop.
Save cabloo/387f1d6d8fe81752574d to your computer and use it in GitHub Desktop.
VBScript mini CURL
Set colNamedArguments = WScript.Arguments.Named
url = colNamedArguments.Item("url")
data = ""
ContentType = "application/x-www-form-urlencoded"
If colNamedArguments.Exists("method") Then
method = colNamedArguments.Item("method")
Else
method = "GET"
End If
If colNamedArguments.Exists("json") Then
ContentType = "application/json"
End If
If colNamedArguments.Exists("dataFile") Then
Set objFS = CreateObject("Scripting.FileSystemObject")
dataFile = colNamedArguments.Item("dataFile")
Set dataFileHandle = objFS.OpenTextFile(dataFile)
Do Until dataFileHandle.AtEndOfStream
data = data & dataFileHandle.ReadLine
Loop
dataFileHandle.Close
End If
dim xmlhttp: Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open method, url, False
xmlhttp.setRequestHeader "Content-Type", ContentType
xmlhttp.send data
WScript.Echo xmlhttp.responseText
Set xmlhttp = Nothing
@cabloo
Copy link
Author

cabloo commented Mar 21, 2016

example usage:

' GET request
cscript \\samba\share\scripts\curl.vbs /url:http://example.com/

' POST request with URL encoded POST data in a file
cscript \\samba\share\scripts\curl.vbs /url:http://example.com/ /dataFile:urlEncodedData.txt /method:POST

' POST request with JSON POST data in a file
cscript \\samba\share\scripts\curl.vbs /url:http://example.com/ /dataFile:jsonData.txt /method:PATCH /json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment