浏览器请求转MockMvc测试controller
操作步骤
- 将代码内容复制到tool.html并保存,使用浏览器打开此文件;
- 打开目标页面的浏览器控制台,筛选需要的请求后,右键->复制->以HAR格式复制所有;
- 将第1步的结果,粘贴到工具里的第一个输入框,点击‘解析’,之后会将HAR的信息,解析出来,并在页面下方生成表格,只会保留xhr请求;
- 点击每个请求右侧的’生成‘按钮,即可自动生成代码,生成完毕后,默认自动选中复制;
代码
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>请求转mockmvc请求</title>
<script src="./lib/jquery-3.7.1.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
.container {
border: none;
width: 75%;
}
textarea {
resize: unset;
width: 100%;
height: 10em;
text-indent: 2em;
font-family: consolas, serif;
font-size: 1em;
border-radius: 20px;
}
.btn {
border: 1px solid #1c936c;
width: 5em;
height: 3em;
border-radius: 20px;
font-size: 1em;
font-family: "楷体", serif;
margin-bottom: 1em;
}
#fa table {
width: 100%;
}
td .path {
width: 20em;
overflow: hidden;
}
td .method {
width: 2em;
overflow: hidden;
}
td .param {
width: 5em;
overflow: hidden;
}
td .opt {
width: 2em;
}
</style>
</head>
<body>
<div class="container">
<textarea
id="har"
cols="25"
rows="10"
placeholder="