Skip to content

Instantly share code, notes, and snippets.

@SteGriff
Created February 2, 2017 16:24
Show Gist options
  • Select an option

  • Save SteGriff/4f1684298b460268ab60ef53549cf41d to your computer and use it in GitHub Desktop.

Select an option

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)
//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