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

};

相关推荐
IT_陈寒1 小时前
Vite的热更新突然不香了,排查三小时差点砸键盘
前端·人工智能·后端
子兮曰1 小时前
Agency-Agents 深度解析:400+ AI 专家的"梦之队"如何重塑开发工作流
前端·后端·vibecoding
竹林8182 小时前
用 The Graph 查询链上数据实战:从手搓 RPC 到 Subgraph,我的 NFT 项目数据加载快了 10 倍
前端·javascript
妙码生花2 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十九):点选验证码代码逐行目检
前端·后端·go
Awu12273 小时前
⚡从零开发 Agent CLI(五)实现一个可治理、可扩展的工具系统
前端·人工智能·claude
咪库咪库咪4 小时前
Vue3-生命周期
前端
莪_幻尘4 小时前
你的 AI Skill 越多越蠢?Token 上下文爆炸的求生指南
前端·ai编程
lichenyang4534 小时前
从 has.echo 到异步 API 注册表:一次 ASCF API 回调不触发的排查复盘
前端
林瞅瞅5 小时前
Nuxt3 项目部署 Nginx 防盗链后特定 JS 文件 403 问题修复方案
前端
kyriewen5 小时前
别再每次都 Google 了:我整理了前端日常最常踩的 10 个 Git 坑,附速查表
前端·javascript·git