51Testing软件测试论坛
标题:
浏览器测试post请求看大神是怎么做的
[打印本页]
作者:
lsekfe
时间:
2022-12-16 10:53
标题:
浏览器测试post请求看大神是怎么做的
需要的代码如下(注意修改url和参数):
var url = "http://localhost:7788/user/save";
var params = {"name":"zhangsan","id":1,"age":16,"address":"南京"}; //此为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);
};
复制代码
[attach]145985[/attach]
[attach]145986[/attach]
[attach]145987[/attach]
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2