侧边栏壁纸
博主头像
Blog博主等级

行动起来,活在当下

  • 累计撰写 211 篇文章
  • 累计创建 94 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

postman简单使用

一、前置条件

  • 前端:spring-boot(搭建方式参考:链接

  • 后端:linux、mongodb(可视化工具:Robo 3T,搭建方式参考:link

  • 测试url: localhost:8080/user

二、postman 使用方法示例

1.post方法

userId 字段的值随机获取,createTime字段的值是当前系统时间。

Headers设置

post-Headers-min.webp

body设置

post-body-min.webp

{
    "userId": "{{generated_userId}}",
    "name": "com3",
    "age": 20,
    "creatTime": "{{current_timestamp}}"
}

Pre-request Script设置

post-Pre-requestscript-min.webp

function generateObjectId() {
    const timestamp = Math.floor(new Date().getTime() / 1000).toString(16);
    const machineIdentifier = '0aa495'; // 3字节机器标识符的示例
    const processId = '9555';           // 2字节进程ID的示例
    const counter = Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, '0'); // 3字节计数器

    return timestamp + machineIdentifier + processId + counter;
}

// 将生成的 ObjectId 存储到环境变量
pm.environment.set("generated_userId", generateObjectId());

// 获取当前时间
const currentTimestamp = new Date().toISOString();
pm.environment.set("current_timestamp", currentTimestamp);

2.get 方法

get-min.webp

3.delete 方法

删掉userId为"666d55670aa4959555d6b703" 的数据

delete-min.webp

再次使用get方法查看该条数据是否还存在

get2-min.webp

0

评论区