//先在浏览器中打开http://8.8.8.8:9081/oil/oilinfo地址,然后在控制台中执行如下代码即可
//创建异步对象
var xhr = new XMLHttpRequest();
xhr.open('post', 'http://8.8.8.8:9081/oil/oilinfo' );
// xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-Type", "application/json")
//发送请求
xhr.send(JSON.stringify({"type": 20,"version":" ZX1.0","YPLE":"01","JYSL":"10.80","JPDJ":"5.6","JYJE":"60.48","JYQH":"01","SJ":" 3F2504E0-4F89-11D3-9A0C-0305E82C3301"}));
xhr.onreadystatechange = function () {
//判断服务器是否正确响应
if (xhr.status == 200) {
console.log(xhr.responseText);
}
else{
console.log("出错了"+ xhr.statusText);
}
};
执行结果: