chrome 模拟发送POST请求和GET请求

F12打开Console输入以下代码:

POST请求

var url = "http://ip地址:8080/test/?id=26323";

var params = {"billIds":"56141305725718528","billType":"VBNSC"};

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);

};

GET请求

var url = "http://IP:8080/testGet?id=235";

var xhr = new XMLHttpRequest();

xhr.open("GET", 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();

xhr.onerror = function (e) {

console.error(xhr.statusText);

};

相关推荐
默_笙28 分钟前
🚍 一条 Todo 的奇幻漂流:TypeScript 全栈类型安全的"护照检查"
前端·javascript
计算机魔术师1 小时前
NVIDIA 以 129.3 亿美元收购 Hugging Face
前端
平头哥技术团队1 小时前
Day 01 | 用 HTML 写第一个网页:双击就能在浏览器打开
前端
计算机魔术师2 小时前
两年翻45倍!英伟达靠买买买建成千亿投资帝国
前端
paopaokaka_luck2 小时前
基于springboot3+vue3的精准扶贫管理系统(AI 问答、ECharts 图形化分析)
前端·人工智能·echarts
l1m0_2 小时前
智能电动自行车管理后台实战:AI生成页面与React组件化技巧
前端·react.js·ui·ai·设计
Patrick_Wilson3 小时前
为什么gitlab的MR会默认有一个merge commit
前端·git·gitlab
en.en..3 小时前
Linux mmap 内存映射深度解析:基于帧缓冲 /dev/fb0
java·服务器·前端
后台模板学习3 小时前
从0到1用Vite构建电商订单系统前端性能优化方案
前端
Wang's Blog3 小时前
Vibe Coding一人即团队系列58: HTML演示文稿自动生成
前端·人工智能·html