URL编码邮递员变量? [英] URL encode Postman variable?

查看:22
本文介绍了URL编码邮递员变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I use Postman for REST API testing and parametrize tests with global variables.

I should put a phone number into GET request: /path/get?phone={{phone}} but leading + sign in the phone number is interpreted as a space.

What is the syntax to URL encode global variables in Postman? Is it possible to run JS encodeURIComponent() on variable in URL?

解决方案

Use the Pre-request scripts (it's next to body) for this:

var encoded = encodeURIComponent({{phone number}});

or

var encoded = encodeURIComponent(pm.environment.get("phone number"));

and to proceed, use:

pm.environment.set("encoded phone number", encoded);

And set your URL to /path/get?phone={{encoded phone number}}

这篇关于URL编码邮递员变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆