Created
February 2, 2017 16:24
-
-
Save SteGriff/4f1684298b460268ab60ef53549cf41d to your computer and use it in GitHub Desktop.
Send a POST request with Windows Script Host (when PowerShell is not available)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Run me with cscript.exe | |
| //Thanks https://gist.github.com/duncansmart/5821523 | |
| //Create easy reference to stdout for logging | |
| var Console = WScript.StdOut; | |
| //Create XHR object | |
| var xhr = WSH.CreateObject("Microsoft.XMLHTTP"); | |
| var url = "http://www.some-url-to-ping/api/initialise"; | |
| //Build POST request - false=synchronous (async doesn't seem to work) | |
| xhr.open("POST", url, false); | |
| //Send (and await result) | |
| Console.WriteLine("Sending..."); | |
| xhr.send(null); | |
| //When response arrives, we'll print HTTP status code and response | |
| Console.WriteLine("HTTP " + xhr.status); | |
| Console.WriteLine(xhr.responsetext); | |
| Console.WriteLine("HTTP " + xhr.status); | |
| Console.WriteLine("Finished"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment