postman-set

1、

<script>
    let authorization = pm.environment.get("Authorization");
    console.log("======= authorization " + authorization);
    if (authorization != null && authorization !== "") {
        // 设置一个请求头
        pm.request.headers.upsert({
            key: 'Authorization', // 请求头名称
            value: authorization// 请求头值
        });
    } else {
        let cookie = pm.environment.get("Cookie");
        console.log("======= cookie " + cookie);
        if (cookie != null && cookie !== "") {
            // 设置一个请求头
            pm.request.headers.upsert({
                key: 'Cookie', // 请求头名称
                value: cookie// 请求头值
            });
        }
    }
</script>
posted @ 2024-03-19 10:15  一只桔子2233  阅读(2)  评论(0编辑  收藏  举报