Postman-接口测试工具

  |   0 评论   |   0 浏览

Postman-接口测试工具

1.Postman 介绍

1.Postman 是什么

  1. Postman 是一款功能超级强大的用于发送 HTTP 请求的 测试工具
  2. 做 WEB 页面开发和测试的人员常用工具
  3. 创建和发送任何的 HTTP 请求(Get/Post/Put/Delete...)

2.Postman 相关资源

1.官方网站 https://www.postman.com/

2.文档 https://learning.postman.com/docs/getting-started/introduction/

3.Postman 安装

具体安装步骤

● 下载 Postman 软件

地址: https://www.postman.com/downloads/

image-20220604104912403

● 安装

  1. 双击即可安装(非常简单), Postman 不会让你选择安装路径,会直接安装,一般安装在 系统盘.
  2. 安装成功,在桌面上有快捷图标.

2.Postman 快速入门

1.快速入门需求说明

● 要求: 使用 Postman 向 http://www.baidu.com 发出 get 请求,得到返回的 html 格式 数据

image-20220604114500098

2.快速入门-实现步骤

  1. 先注册 Postman 一个账号: 这个比较简单,输入邮箱,添加账号名和密码即可
  2. 登录 Postman(登录后会进行数据同步)

image-20220604114626007

  1. 进入 Postman

image-20220604114822172

3.Postman 完成简单的Controller层测试

说明: 使用 Postman ,完成对编写好的 UserHandler 方法的请求

这里我项目的配置的工程路径是springmvc,因此请求的url是http://localhost:8080/springmvc/接口地址

1.POST请求

@PostMapping(value = "/user/buy")
public String buy() {
    System.out.println("购买商品~");
    return "success";
}

这里接口没有特殊的参数需要传,对header参数也没有要求,所有直接发起Post请求即可

image-20220604115825426

2.GET请求

@RequestMapping(value = "/user/find", params = "bookId=100", method = RequestMethod.GET)
public String search(String bookId) {
    System.out.println("查询书籍 bookId= " + bookId);
    return "success";
}

请求方式:GET、必传参数:bookId且值必须为100

image-20220604120044949

3.@RequestMapping-默认支持GET/POST请求

这里我们在@RequestMapping中没有指定请求的方式,默认是支持get和post请求的

@RequestMapping(value = "/user/hi")
public String hi() {
    System.out.println("hi");
    return "success";
}

GET请求

image-20220604120553210

POST请求

image-20220604120631054

4.匹配多层路径的请求

@RequestMapping(value = "/user/message/**")
public String im() {
    System.out.println("发送消息");
    return "success";
}

image-20220604121001772

5.请求地址获取参数

@RequestMapping(value = "/user/reg/{username}/{userid}")
public String register(@PathVariable("username") String name,
                       @PathVariable("userid") String id) {
    System.out.println("接收到参数--" + "username= " + name + "--" + "usreid= " + id);
    return "success";
}

image-20220604121613412

6.DELETE请求

@DeleteMapping(value = "/delete")
public void delete(){
    System.out.println("删除成功");
}

image-20220604122055322


标题:Postman-接口测试工具
作者:llp
地址:https://llinp.cn/articles/2022/06/04/1654316707688.html