浏览器/CMD 模拟post请求 传送json格式数据

1.cmd 

curl http://localhost:8080/****** -X POST -d {"""code""":"""201""","""passTime""":"""2022-06-14 17:00:00"""} -H "Content-Type:application/json" -k

2.谷歌浏览器

  步骤:F12 ->console (中文:控制台)

  输入:

var url = "http://localhost:8080/save";
var params = {"code":"201","passTime":"2022-06-14 17:00:00"}; //此为json格式的参数
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onload = function (e) {
if (xhr.readyState === 4) {
    if (xhr.status === 200) {
    console.log(xhr.responseText);
    } else {
    console.error(xhr.statusText);
    }
    }
};
xhr.send(JSON.stringify(params));
xhr.onerror = function (e) {
console.error(xhr.statusText);
};

ps:只在win10上测试可用,其余的未测试!

posted @ 2022-06-14 18:06  资深CURD小白程序猿  阅读(2670)  评论(0编辑  收藏  举报