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

};

相关推荐
小二·7 分钟前
Python Web 开发进阶实战:数字孪生平台 —— 在 Flask + Vue 中构建实时物理世界镜像
前端·vue.js·python
CHU7290359 分钟前
安心陪伴,便捷就医:陪诊代办小程序的温暖设计
前端·小程序·php
ashcn200116 分钟前
websocket测试通信
前端·javascript·websocket
weixin_4046793119 分钟前
edge alt tab怎么关
前端·edge
CHU72903535 分钟前
线上扭蛋机拆盒小程序前端功能版块解析
前端·小程序·php
卿着飞翔1 小时前
Vue使用yarn进行管理
前端·javascript·vue.js
夏天想1 小时前
vue通过iframe引入一个外链地址,怎么保证每次切换回这个已经打开的tab页的时候iframe不会重新加载
前端·javascript·vue.js
GISer_Jing1 小时前
2026年前端开发目标(From豆包)
前端·学习·aigc
军军君011 小时前
Three.js基础功能学习十一:动画与音频
前端·javascript·3d·js·threejs·三维
我即将远走丶或许也能高飞1 小时前
reduxjs/toolkit 的学习使用
前端·javascript·学习·reactjs