理解HTTP 以及REST
testhttputility.bat
wscript GET http://msdn.microsoft.com/en-us/ff972295
httputility.js
if (WScript.Arguments.length < 2)
{
WScript.echo("Client HTTP Request Utility\n");
WScript.echo("usage: httprequest method uri [options]");
WScript.echo();
WScript.echo(" -f filename");
WScript.echo(" -h headerName headerValue");
WScript.Quit(1);
}
var method = WScript.Arguments.Item(0);
var uri = WScript.Arguments.Item(1);
var req = new ActiveXObject("MSXML2.XMLHTTP");
var filename = null;
req.Open(method, uri, false);
WScript.echo();
WScript.echo("********* Request ********* ");
WScript.echo(method + " " + uri + " HTTP/1.1");
for (i=2; i < WScript.Arguments.length; i++)
{
var option = WScript.Arguments.Item(i);
if (option == "-f")
filename = WScript.Arguments.Item(i+1);
if (option == "-h")
{
WScript.echo(WScript.Arguments.Item(i+1) + ": " +
WScript.Arguments.Item(i+2));
req.setRequestHeader(WScript.Arguments.Item(i+1),
WScript.Arguments.Item(i+2));
}
}
try
{
if (filename != null)
{
WScript.echo();
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(filename, 1, false);
var fileContents = file.ReadAll();
file.Close();
WScript.echo(fileContents);
req.Send(fileContents);
printResponse(req);
}
else
{
req.send();
printResponse(req);
}
}
catch(e)
{
WScript.echo();
WScript.echo("******* Response ********* ");
WScript.echo(e.message);
}
function printResponse(req)
{
WScript.echo();
WScript.echo("******* Response ********* ");
WScript.echo("HTTP/1.1" + " " + req.status + " " + req.statusText);
var headers = req.getAllResponseHeaders();
WScript.echo(headers);
WScript.echo(req.responseText);
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步