当前位置:网站首页>【测试平台开发】21. 完成发送接口请求显示响应头信息
【测试平台开发】21. 完成发送接口请求显示响应头信息
2022-07-23 09:01:00 【把苹果咬哭的测试笔记】
基于 springboot+vue 的测试平台(练手项目)开发继续更新。
在接口编辑页中点击发送接口请求,除了显示响应体外,还可以显示响应头等辅助信息,今天完成这个功能的开发。

一、后端实现
后端主要是修改一下处理接口发送请求的方法apiTestRun,之前这个方法返回的直接就是一个响应体,现在修改成返回更多的内容。

如图所示,注释掉的部分是之前的返回。
在 hutool 的 http 客户端中,httpResponse对象是包含了很多信息的,这里目前只先用这几个:body、cookies、responseStatus、responseHeaders。获取到之后放到一个新的对象里返回出去。
不过前端的页面目前也只需要用body和responseHeaders这2个,前者是替换到之前的显示,后者就是今天新增的功能所需要的。
二、前端实现
1. 返回的数据放到 vuex 中
在 vuex 中,我把接口返回的信息从接口请求对象中拿了出来,保存的时候就不做落库了。

所以,现在发送请求成功后,要把获取到的信息赋值给 vuex 中的对应字段。因为返回内容改了,所以body的赋值也要重新改下,再加上新增的respHeaders赋值即可。

2. 从 vuex 中获取数据并展示
新建一个组件ResponseHeaders,在这里获取到 vuex 中的数据并展示出来。
<template>
<el-card class="box-card">
<div v-for="(i, v) in headersObj" :key="v" class="text item">
{
{ v + ':' + i }}
</div>
</el-card>
</template>
<script>
export default {
name: 'ResponseHeaders',
data() {
return {
headersObj: {}
}
},
computed: {
respHeaders() {
return this.$store.state.apiDefinition.responseInfo.respHeaders
}
},
watch: {
respHeaders: {
handler() {
this.headersObj = this.respHeaders[0]
},
immediate: true,
deep: true
}
}
}
</script>这里直接使用 elementui 中的<el-card>组件简单显示出来即可。
最后,新建的这个组件ResponseHeaders放到一个父组件ResponseInfoBase中。
<template>
<div>
<el-divider content-position="left">响应内容</el-divider>
<el-tabs v-model="activeName">
<el-tab-pane label="响应体" name="respBody">
<ResponseBody />
</el-tab-pane>
<el-tab-pane label="响应头" name="respHeaders">
<ResponseHeaders />
</el-tab-pane>
</el-tabs>
</div>
</template>
<script>
import ResponseBody from '@/views/apiManagement/definition/responseContent/ResponseBody'
import ResponseHeaders from '@/views/apiManagement/definition/responseContent/ResponseHeaders'
export default {
name: 'ResponseInfoBase',
components: { ResponseBody, ResponseHeaders },
data() {
return {
activeName: 'respBody'
}
}
}
</script>这个父组件是集中存放关于接口响应相关内容的地方,另一个响应体ResponseBody也是在这里,并且使用<el-tabs>来显示。
最新代码都已更新,如果也想动手的童鞋可以在公众号回复【测试平台】,可以获取 github 地址以及开发记录系列文章。
边栏推荐
- 【 langage c】 devinez jeux numériques + applet d'arrêt
- 第4章 集合运算
- 494. 目标和
- C语言实现memcpy、memmove
- CPU, memory, disk speed comparison
- 10年软件测试工程师经验,很茫然....
- Chapitre 2 requête de base et tri
- C语言项目实战:24点游戏计算器(基于结构体、指针、函数、数组、循环等知识点)
- Uni app knowledge points and records of problems and solutions encountered in the project
- koa框架的使用
猜你喜欢

C language implementation of classroom random roll call system

Right click to create a new TXT. The new text file is missing. You can solve it by adding a registry. Find the ultimate solution that can't be solved

After using vscode to format the code, save and find that the code is messy again. What should I do? Vs remove formatting

OKRK3399开发板预留I2C4挂载EEPROM

【小程序自动化Minium】一、框架介绍和环境搭建

Towhee 每周模型

多重背包!

基于EFR32MG24的AI 加速度姿势识别体验

Dynamic programming -- knapsack problem

Authing 支持 Zadig 啦!云原生用户统一认证快速对接
随机推荐
Authing 支持 Zadig 啦!云原生用户统一认证快速对接
Canvas from getting started to persuading friends to give up (graphic version)
Canvas 从入门到劝朋友放弃(图解版)
338. 比特位计数
Using JS to parse and execute XSS automatically
First acquaintance and search set
Tell you Web3.0 I understand
基金开户网上办理是否安全?谁给解答一下
104 maximum depth of binary tree and 543 diameter of binary tree and 124 maximum path sum of binary tree
Sword finger offer 46. translate numbers into strings
優化華為雲服務器采用Key登陸
C language implements StrCmp, strstr, strcat, strcpy
【小程序自动化Minium】三、元素定位- WXSS 选择器的使用
ValidationError: Invalid options object. Dev Server has been initialized using an options object th
Pacific Atlantic current problem
FFmpeg 2 - ffplay、ffprobe、ffmpeg 命令使用
Palindrome related topics
JS texture style pie chart plug-in
云呐-如何加强固定资产管理?怎么加强固定资产管理?
Aruba学习笔记05-配置架构- WLAN配置架构