JavaScript之简易http接口测试工具网页版
简易http接口测试工具网页版,支持get、post请求,支持json格式消息体,form表单暂不支持。
httpClient.html
<!DOCTYPE html>
<html lang="en">
<!--模仿postman编写一个简易的http接口测试工具-->
<head>
<meta charset="UTF-8">
<title>自定义HttpClient</title>
<link rel='stylesheet prefetch' href='https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="../css/httpClientStyle.css">
<script src="../js/httpclient.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h3 class="page-header">接口测试工具</h3>
<div>
<label>接口地址:</label>
<input type="text" class="form-control" id="url_input"
value="http://localhost:8080/getStudentByIdWithJson">
<!--<label>接口类型:</label><input type="text" class="form-control" id="type_input" value='POST'>-->
<div>
<label>接口类型:</label>
<select id="type_select" class="selected form-select-button" style="height: 25px">
<option value="GET">GET</option>
<option value="POST" selected>POST</option>
</select>
</div>
<label>消息头:</label><input type="text" class="form-control" id="header_input" title='{"A":"XX","B":"XX"}'> <label>消息体:</label>
<div>
<input name="bodyType" type="radio" value="form"> Form 
<input name="bodyType" type="radio" value="json" checked> JSON
</div>
<input type="text" class="form-control" id="body_input" value='{"id":"1"}'>
</div> <div class="btn-group">
<button type="submit" class="btn btn-primary" title="发送消息" onclick="send()">发送</button>
<button type="reset" class="btn btn-primary" title="刷新页面" onclick="location.reload()">刷新</button>
<button type="reset" class="btn btn-primary" title="清空查询结果" onclick="clearShowArea()">清空</button>
<button type="reset" class="btn btn-primary" title="跳转首页" onclick="location.href='/'">首页</button>
</div> <div>
<label>返回结果:</label>
<div class="well">
<p id="showArea"></p>
</div>
</div>
</div> </div> </body>
</html>
httpclient.js
//处理json数据
function getOneByForm() {
var url = $("#url_input").val();
var body = $("#body_input").val();
var type = $("#type_select").val();
var headers = $("#header_input").val(); $.ajax({
url: url,//请求地址
// data: {id: 3},//提交的数据
data: body.toString(),//提交的数据
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
type: type,//提交的方式
dataType: "TEXT", //返回类型 TEXT:字符串 JSON XML
headers: {headers},
success: function (data) { // 校验返回内容,进行跳转
//将获取到的数据输出到元素上
$("#showArea").text(data);
console.log(data);
},
error: function (xhr) {
clearShowArea();
// 失败输出HTTP状态码
alert("调用失败!HTTP状态码:" + xhr.status);
}
})
} function getOneByJson() {
var url = $("#url_input").val();
var body = $("#body_input").val();
var type = $("#type_select").val();
var headers = $("#header_input").val();
$.ajax({
url: url,//请求地址
data: body,//提交的数据
contentType: "application/json; charset=utf-8",
headers: {headers},
type: type,//提交的方式
dataType: "TEXT", //返回类型 TEXT:字符串 JSON XML
success: function (data) { // 校验返回内容,进行跳转
//将获取到的数据输出到元素上
$("#showArea").text(data);
console.log(data);
},
error: function (xhr) {
clearShowArea();
// 失败输出HTTP状态码
alert("调用失败!HTTP状态码:" + xhr.status);
}
})
} // 清空结果
function clearShowArea() {
$("#showArea").empty();
} // 发送请求方法入口,判断数据类型分别调用对应方法
function send() {
var bodyType = $('input:radio[name=bodyType]:checked').val();
console.log("bodyType: " + bodyType)
if (bodyType == "form") {
getOneByForm();
} else if (bodyType == "json") {
getOneByJson();
} else {
alert("不支持该类型:" + bodyType)
}
} function jsonToFormData(json) {
var object = JSON.parse(body);
var rs = "";
object.key(obj).forEach()
{
rs = {}
}
} // 跳转首页
function toIndex() {
window.location.href = '/';
}
httpClientStyle.css
/*
httpClient demo的样式
*/ label {
/*margin: 10px;*/
margin-top: 12px;
/*margin-bottom: 20px;*/
} div {
margin-top: 10px;
margin-bottom: 10px;
}
截图:

JavaScript之简易http接口测试工具网页版的更多相关文章
- javascript实现移动端网页版阅读器
现在手机上的文本阅读app已经非常丰富,良好的阅读体验与海量的书库常常令我感到无比兴奋. 我想到8年前用一点几寸屏幕的mp3看电子书的情景,顿生一种淡淡的温馨.再久远一些,小的时候,我也经常和小伙伴们 ...
- 利用 JavaScript SDK 部署网页版“Facebook 登录”
facebook开发者平台https://developers.facebook.com/ 利用 JavaScript SDK 部署网页版“Facebook 登录” 通过采用 Javascript 版 ...
- JavaScript 实现简易版贪吃蛇(Day_13)
时光永远在变迁,你始终要丢下过去. 使用语言 JavaScript 概述 运用JavaScript 实现简易版<贪吃蛇>. Html 页面 1 <!DOCTYPE htm ...
- Python接口测试实战1(下)- 接口测试工具的使用
如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...
- 分享:计算机图形学期末作业!!利用WebGL的第三方库three.js写一个简单的网页版“我的世界小游戏”
这几天一直在忙着期末考试,所以一直没有更新我的博客,今天刚把我的期末作业完成了,心情澎湃,所以晚上不管怎么样,我也要写一篇博客纪念一下我上课都没有听,还是通过强大的度娘完成了我的作业的经历.(当然作业 ...
- Remoting接口测试工具
动手写一个Remoting接口测试工具 基于.NET开发分布式系统,经常用到Remoting技术.在测试驱动开发流行的今天,如果针对分布式系统中的每个Remoting接口的每个方法都要写详细的测试脚本 ...
- Dreamweaver杀手!Illustrator终结者?Flash的末日?图形图像设计程序之网页版
Dreamweaver杀手!Illustrator终结者?Flash的末日?图形图像设计程序之网页版 阅读: 评论: 作者:Rybby 日期: 来源:rybby.com Adobe 家的 Il ...
- postman接口测试工具的常规使用
目录 postman接口测试工具简介与安装 postman发送get请求 JSON数据详解 postman发送post请求 postman中post请求传参说明 postman设置请求的header ...
- Springboot整合WebSocket实现网页版聊天,快来围观!
随机推荐
- extjs 中的一些鲜为人知的属性(深渊巨坑)
1. new Ext.form.FormPanel 组件中,去除边框属性为:baseCls:'my-panel-no-border', 2.当 new Ext.form.FormPanel 嵌套b ...
- Ubuntu16.04安装和使用ElasticSearch
1.下载es wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/ela ...
- 在使用 Spring Boot 和 MyBatis 动态切换数据源时遇到的问题以及解决方法
相关项目地址:https://github.com/helloworlde/SpringBoot-DynamicDataSource 1. org.apache.ibatis.binding.Bind ...
- 在ASP.NET Core MVC中子类Controller拦截器要先于父类Controller拦截器执行
我们知道在ASP.NET Core MVC中Controller上的Filter拦截器是有执行顺序的,那么如果我们在有继承关系的两个Controller类上,声明同一种类型的Filter拦截器,那么是 ...
- LDAP2-创建OU创建用户
创建OU创建用户 1.创建OU 选择Organisational unit 组织单元 输入OU名称 提交信息 结果创建成功 2.创建员工 选择ou选择新建子条目 选择默认模板 选择inetorgper ...
- vue 中给组建绑定原生事件@click.native=""
<template> <div class="div"> //组建使用 <v-header @click.native=& ...
- Luogu P4323 [JSOI2016]独特的树叶
一道比较好的树Hash的题目,提供一种不一样的Hash方法. 首先无根树的同构判断一般的做法只有树Hash,所以不会的同学可以做了Luogu P5043 [模板]树同构([BJOI2015]树的同构) ...
- .net core实践系列之短信服务-架构设计
前言 上篇<.net core实践系列之短信服务-为什么选择.net core(开篇)>简单的介绍了(水了一篇).net core.这次针对短信服务的架构设计和技术栈的简析. 源码地址:h ...
- LeetCode 657. Robot Return to Origin
There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its mov ...
- C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 严格的用户账户审核功能
整个集团有几万个用户,一个个用户添加是不现实的,只有每个公司的系统管理员添加.或者用户申请帐户,然后有相应的管理员审核,才会更准确一些. 每个公司.分公司.部门的账户情况只有所在公司的管理员是最清楚的 ...