GET、POST、PUT、DELETE请求测试项

利用的是命令行cscript  **.js

GET

var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");

httpRequest.open("GET", "http://localhost:8088/budgetExecuteItem/get", false);

var data=["id=8"];

httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  //默认form的字符串传送数据
//httpRequest.setRequestHeader("Content-Type", "application/json"); //JSON数据
httpRequest.send(data.join('&'));
//httpRequest.send(JSON.stringify(data));


WScript.Echo(httpRequest.responseText);


POST

var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");

httpRequest.open("POST", "http://localhost:8088/budgetExecuteItem/post", false);


var data ='{"id":"1","budgetId":"1","projectId":"1","typeLevel1":"3","typeLevel2":"3","typeLevel3":"3","typeLevel4":"TTTTT","budgetCode":"BBBBB","money":"3000","executeTime":"2017-11-06","remarks":"xxxx"}';
//httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");


httpRequest.setRequestHeader("Content-Type", "application/json");
//httpRequest.send(data.join('&'));
 
//httpRequest.send(JSON.stringify(data)); 
httpRequest.send(data);


WScript.Echo(httpRequest.responseText);


PUT

var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");




httpRequest.open("PUT", "http://localhost:8088/budgetExecuteItem/put", false);


var data ='{"id":"1","budgetId":"1","projectId":"1","typeLevel1":"3","typeLevel2":"3","typeLevel3":"3","typeLevel4":"YYYY","budgetCode":"AAAA","money":"6000","executeTime":"2017-11-06","remarks":"xxxx"}';
//httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");


httpRequest.setRequestHeader("Content-Type", "application/json");
//httpRequest.send(data.join('&'));
 
//httpRequest.send(JSON.stringify(data)); 
httpRequest.send(data);


WScript.Echo(httpRequest.responseText);


DELETE

var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");




httpRequest.open("DELETE", "http://localhost:8088/budgetExecuteItem/delete?id=1", false);


var data=["id=1"];


httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//httpRequest.setRequestHeader("Content-Type", "application/json");
httpRequest.send();
//httpRequest.send(JSON.stringify(data));


WScript.Echo(httpRequest.responseText);


你可能感兴趣的:(GET、POST、PUT、DELETE请求测试项)