postman可以测试加密接口测试工具postman吗

关于调用接口的详细说明关于调用接口的详细说明百度经验百家号以2.获取电站信息列表为例,简单介绍接口的调用;第一步,下载谷歌插件,参考http://jingyan.baidu.com/article/48a4a.html此文档即可成功安装谷歌插件。第二步,打开谷歌插件PostMan调用接口(先调用获取access_token的接口,在调用获取电站信息列表的接口)。请使用这个颜色的PostMan插件奥!!第一步 ,调用获取access_token的接口,调用地址为 :http://api.wyqcd.net:8004/OAuth/Token,在Header中配置请求方式Content-Type为application/x-www-form-urlencoded,以Post方式请求,配置Post参数,client_id:telds7t15qrwgw7gu5owclient_secret:v9yOJBXhS2grant_type:client_credentials配置完成点击《发送》按钮,即可得到返回数据。第二步,获取到Token数据后,调用获取电站信息列表的接口,此时用到报文转换工具,下面对报文转换工具做详细介绍。(1)商户号,Key,Secret ,DesKey ,SesIV 是对一个公司的身份标示,请配置为:商户号 & &telds7t15qrwgw7gu5owKey & & & &q34vJSrNCtqbzWIctvXEYF6DNy2m8X9+Secret & &v9yOJBXhS2DesKey & RWYsASCXSesIV & & 90H3NHHfjfDA23MKSad7HmgXr3O8MEKm(2)请求报文转换,此处为请求的数据,在提供的html中是以{&&& &requestMsg&: {&&&&&&& &province&: &山东&,&&&&&&& &city&: &青岛&,&&&&&&& &region&: &&,&&&&&&& &type&: &&,& & & && &opState&: &&,& & & && &pageNo&: &1&,& & & && &pageSize&: &100&&&& },&&& &sign&: &724b54a9ddee845f5d5546421cca337f&}此种格式存在的,那么在请求报文转换的文本框中只需要将{&province&: &山东&,&city&: &青岛&,&region&: &&,&type&: &&,&opState&: &&,&pageNo&: &1&,&pageSize&: &100&}Json格式的数据放到文本款中即可,因为请求数据都是加密的形式请求的,所以请勾选【加密】选项,点击【转换】按钮,即可在Label中呈现加密的数据以及对加密数据的签名;(3)响应报文解密文本框,如果请求数据是以加密形式传递,那么响应的报文也是加密形式返回的,需要对数据进行解密,将返回的所有数据放到响应报文解密文本框中,点击【解密】按钮,即可在Label中呈现解密的数据以及对解密数据的签名。第三步,调用获取电站信息列表的接口,在PostMan中配置请求地址:http://api.wyqcd.net:8004/api/Sta/PostSta,在Header中配置请求方式Authorization为Bearer [此处为获取access_token的接口返回的access_token的值],Content-Type为application/ charset=utf-8,以Post方式请求,配置Post参数,在row中将报文转换工具的加密数据全部复制到此处即可第四步,调用电站列表接口返回的数据为加密数据,需要对加密数据进行解密处理,此处将返回的所有数据全部复制到报文转换工具的响应报文解密文本框中即可;方法调用成功啦,方法的请求只要是Http &Post 的形式就可以啦;本文仅代表作者观点,不代表百度立场。系作者授权百家号发表,未经许可不得转载。百度经验百家号最近更新:简介:解决你所有的生活难题作者最新文章相关文章1、如下图,需要获取applyJsonStr 中 name,idCard和empNo,并连接这3个值为一个字符串,通过MD5加密,生成下一个请求需要的值。
2、在tests中使用request.data可以获取请求中数据。
使用request.data.applyJsonStr获取applyJsonStr的值。
然后使用jsonData["name"]、jsonData["idCard"]和jsonData["empNo"],分部获取name,idCard和empNo的值。
3、使用CryptoJS.MD5(str).toString() 将str进行MD5加密并转为字符串。
toUpperCase()是将小写字母转为大写。不需要用到的话,可以去掉。
4、将生成的md5设置为环境变量,以供下一个请求使用。
postman.setEnvironmentVariable('md5', md5)
5、在下一个请求中使用{{md5}}赋值
刷屏啦。。。。
后方可回复, 如果你还没有账号请点击这里 。
zxd (丹丹)
第 11677 位会员 /
共收到 1 条回复Postman使用手册4——API test - 简书
Postman使用手册4——API test
一、Pre Request Scripts
Postman v0.10+ 版本支持pre-request scripts。
prerequest script.png
pre-request scripts是一个关联了收藏夹内request,并且在发送request之前执行的代码片段。这对于在request header中包含时间戳或者在URL参数中发送一个随机字符串都是非常有用的。
例如:如果要在request的header中包含一个时间戳,你可以设置一个环境变量由一个函数返回他的值。
postman.setEnvironmentVariable('timestampHeader',new Date());
你可以在header中使 timestampHeader 变量,当request发送的时候,你的pre-request script将被执行,这个timestampHeader 变量的值将会替换{{timestampHeader}}。
注意:我们设置的环境对使用的环境变量必须是有效的。
二、Writing Tests
1.基本结构
![Uploading prerequest script_871640.png . . .]
Basic structure.png
Postman给了你一个环境让你能够为每个request编写、执行你的test,而不用担心任何额外的设置。
一个Postman的test本质上是JavaScript的代码可以用来为一些特殊的test设置值。你可以在对象中设置一个描述性的键作为一个元素,然后声明他如果是true或false。
tests[“Body contains user_id”] = responseBody.has(“user_id”)
这回核对body中是否包含了user_id这个字符串。如果你需要,你可以增加更多的键,这取决于你要用test做多少的事情。
test被保存为收藏夹request的一部分,这对于后端或前端的工程师来确保API运行的正常都是非常有意义的。
2.SNIPPETS
在写test的时候这里有些事情需要注意,Postman尝试使得列出常用的片段更简单。你可以选择你想添加的片段,然后适当的代码将被添加到test的编辑器中。这是一个很好的方法来快速的构建test
3.查看结果
view result.png
Postman在你执行一个request的时候执行test,当然你可以选择不考虑test。结果被显示在一个tab里,并在头部显示多少test通过了测试。你设置在test中的变量将会被列在这里。如果值是true,这个test就会通过。你可以保持test tab活动直到你确保所有的test执行完。
三、Testing Sandbox
Postman的sandbox是一个JavaScript的执行环境,这使得你能够为request写pre-request scripts和test scripts 。不论你写的代码是pre-request scripts还是test script都会在sandbox中执行。
1.常用的库和工具
JS utility library
(Deprecated):
Cross-platform JavaScript library. This will be removed in future versions of the sandbox.
(Deprecated):
Provides simple models, views, and collections. This will be removed in future versions of the sandbox.
Extends native JS objects with useful methods
Validates JSON objects against v4 of the json-schema draft
standard and secure cryptographic algorithms. Supported algorithms: AES, DES, EvpKDF, HMAC-MD5, HMAC-SHA1/3/256/512, MD5, PBKDF2, Rabbit, SHA1/3/224/256/512, TripleDES
xml2Json(xmlString):
This function behaves the same in Newman and Postman
xmlToJson(xmlString)(Deprecated):
This function does NOT behave the same in Newman and Postman
postman.getResponseHeader(headerName) (Test-only):
returns the response header with name "headerName", if it exists. Returns null if no such header exists. Note: According to W3C specifications, header names are case-insensitive. This method takes care of this.
postman.getResponseHeader("Content-type") and postman.getResponseHeader("content-Type") will return the same value.
2.环境和全局变量
postman.setEnvironmentVariable(variableName, variableValue) : Sets an environment variable "variableName", and assigns the string "variableValue" to it. You must have an environment selected for this method to work. Note: Only strings can be stored. Storing other types of data will result in unexpected behavior.
postman.setGlobalVariable(variableName, variableValue):
Sets a global variable "variableName", and assigns the string "variableValue" to it. Note: Only strings can be stored. Storing other types of data will result in unexpected behavior.
postman.clearEnvironmentVariable(variableName):
Clears the environment variable named "variableName". You must have an environment selected for this method to work.
postman.clearGlobalVariable(variableName):
Clears the global variable named "variableName".
postman.clearEnvironmentVariables():
Clears all environment variables. You must have an environment selected for this method to work.
postman.clearGlobalVariables():
Clears all global variables.
environment:
A dictionary of variables in the current environment. Use environment["foo"]
to access the value of the "foo" environment variable.
A dictionary of global variables. Useglobals["bar"]
to access the value of the "bar" global variable.
3.动态变量
Postman也有一些动态变量,你可以用在你的request中。这个现在主要还是在实现阶段,更多的功能以后被被添加进来。注意:动态变量不可以用于SandBox中,你只能在request的URL、headers、body中以放在双花括号中间的形式使用。
{{$guid}}: Adds a v4 style guid
{{$timestamp}}: Adds the current timestamp.
{{$randomInt}}: Adds a random integer between 0 and 1000
4. Cookies
+** responseCookies {array} **(Postman-only):
Gets all cookies set for the domain. You will need to enable the
for this to work.
postman.getResponseCookie(cookieName)(Postman-only):
Gets the response cookie with the given name. You will need to enable the interceptor for this to work. Check out the .
5.Request/response相关属性
request {object}:
Postman makes the request object available to you while writing scripts. This object is read-only. Changing properties of this object will have no effect. Note: Variables will NOT be resolved in the request object. The request object is composed of the following:
data {object}:
this is a dictionary of form data for the request. (request.data["key"]=="value")
headers {object}:
this is a dictionary of headers for the request (request.headers["key"]=="value")
method {string}:
GET/POST/PUT etc.
url {string}:
the url for the request.
responseHeaders {object}(Test-only)(Deprecated):
This is a map of the response headers. This is case-sensitive, and should not be used. Check thepostman.getResponseHeader()
method listed above.
responseBody {string}(Test-only):
A string containing the raw response body text. You can use this as an input to JSON.parse, or xml2Json.
responseTime {number}(Test-only):
The response time in milliseconds
responseCode {object}(Test-only):
Contains three properties:
code {number}:
The response code (200 for OK, 404 for Not Found etc)
name {string}:
The status code text
detail {string}:
An explanation of the response code
tests {object}(Test-only):
This object is for you to populate. Postman will treat each property of this object as a boolean test.
iteration {number}:
Only available in the Collection Runner and Newman. Represents the current test run index. Starts from 0.
(Test-only): This object is only available in the test script section. Using this in a pre-request script will throw an error.
四、Testing 实例
我们来看一些Postman用于test的例子。这些例子中的大多数在Postman中是有效的,他们像一行JavaScript语句一样简答。在你的request中你可以有很多的test。
注意:test脚本在从服务器收到response后执行
1.设置环境变量:
postman.setEnvironmentVariable("key", "value");
2.设置全局变量:
postman.setGlobalVariable("key", "value");
3.检查response的body中是否包含字符串:
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
4.把XML的body转换成JSON对象:
var jsonObject = xml2Json(responseBody);
5.检查response的body是都为一个字符串:
tests["Body is correct"] = responseBody === "response_body_string";
6.检查JSON的值:
var data = JSON.parse(responseBody);
tests["Your test name"] = data.value === 100;
7.内容类型存在(检查不区分大小写)
tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); //Note: the getResponseHeader() method returns the header value, if it exists.
8.内容类型存在(区分大小写):
tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");
9.response的响应时间小于200ms:
tests["Response time is less than 200ms"] = responseTime & 200;
10.状态码为200:
tests["Status code is 200"] = responseCode.code === 200;
11.Code name contains a string:
tests["Status code name has string"] = responseCode.name.has("Created");
12.成功的POST request状态码:
tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;
13.Use TinyValidator for JSON data
var schema = {
"items": {
"type": "boolean"
var data1 = [true, false];
var data2 = [true, 123];
console.log(tv4.error);
tests["Valid Data1"] = tv4.validate(data1, schema);
tests["Valid Data2"] = tv4.validate(data2, schema);
14.Sample data files
JSON files are composed of key/value pairs:
For CSV files, the top row needs to contain variable names
Postman 使用手册系列教程:
在生活的每一个层面都力求完美,寻找自我,创造自我,努力成为一个生活的艺术家。
Why Stock Markets CrashThis page intentionally left blankWhy Stock Markets CrashCritical Events in ComplexFinancial SystemsD i d i e r S ...
astro-ph.IM - 仪器仪表和天体物理学方法cs.AI - 人工智能cs.CE - 计算工程、 金融和科学cs.CL - 计算与语言cs.CV - 机器视觉与模式识别cs.CY - 计算与社会cs.DB - 数据库cs.DC - 分布式、并行与集群计算cs.DS -...
PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE AGREEMENT TERMS AND CONDITIONS CAREFULLY BEFORE DOWNLOADING OR USING THE APPLE ...
**2014真题Directions:Read the following text. Choose the best word(s) for each numbered blank and mark A,B,C or D on the ANSWER SHEET.(10 p...
cs.AI - 人工智能cs.CL - 计算与语言cs.CR - 加密与安全cs.CV - 机器视觉与模式识别cs.CY - 计算与社会cs.DC - 分布式、并行与集群计算cs.DS - 数据结构与算法cs.HC - 人机接口cs.IR - 信息检索cs.IT - 信息论...
从这节开始,难写了。破而不立,容易,破而后立,难。拆别人的台,拆主流的台,意味着留给自己蹦跶的地方也不大。我不是专家,教育学的,心理学的,医学的,更不是“育儿学”的,只是从常识出发,摸着逻辑过河。 在我看来,一个人的世俗教育可大致分为,家庭教育,学校教育,自我教育,职业教育...
今天是五四青年节,因此在这个充满激情与活力,同时只属于那些年轻的日子里,想说一说,你是否走的太快了,以致于忘记了还有一些事情没有做,就这样匆匆的走了,但是不可能再来。丢了什么?什么是最重要的,一个真实存在的就是婚恋,组件一个适合的家庭才是人生最重要的,因为现在不是原始人的社...
这是预览模式标题 一级标题 二级标题 三级标题 四级标题 五级标题 六级标题 列表 无序列表 文本1 文本2 文本3 有序列表 文本1 文本2 文本3 链接和图片 简书 引用 一盏灯, 一片昏黄; 一简书, 一杯淡茶。 守着那一份淡定, 品读属于自己的寂寞。 保持淡定, 才...
喜欢他的第587天. 时间过得很快,转眼就要各奔东西。他曾经说过我们不会分开,可命运又能被谁左右。他说过,只要走进彼此心里,即使死亡,两个人也仍在一起。所以在我心里他不会离开,尽管现实中他也一直在。 他曾经问过为什么地球是圆的。我在心里回答他,地球是圆的是因为不想让那些本该...
大家晚上好。不二法门的朋友这两天刚突破一千的数目。只是单纯地想谢谢大家的支持。 我知道这个数目对于一个公众号来说小得微不足道,但对于不二法门这样一个不做推广(除了寅少的@西政包打听友情赠送的一次推荐,非常感谢他),更新率不高且定位小众(不发“给XXX的10条建议”“XXX要...postman加密请求接口_百度知道
postman加密请求接口
我有更好的答案
这个问题我也不懂,你去后盾人网站看看吧,里面都是一线讲师录制的高清视频,肯定可以帮助到你
采纳率:44%
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。Postman 使用小技巧参数值加密
使用postman进行接口测试时,会经常碰到参数值加密的情况,比如使用签名sign MD5加密,以下为postman进行加密的方法:
参照官方文档:
我们可以通过CryptoJS进行加密,打开postman接口请求界面
在Pre-request Script中输入以下脚本:
var str = environment.variable_1 + environment.variable_2;
var hash = CryptoJS.MD5(str).toString();
postman.setEnvironmentVariable('hash', hash);
然后在请求的url Params里 sign keyvalue中输入{{hash}},就可以将加密值添加到sign里,其他加密方式可参考官方文档和模板来实现。
非常好,不知道postman的这个脚本功能支持的怎么样,是否支持请求体中的数据加密?是否支持google protocol buffer协议数据?
这个是我在工作中碰到的一个问题的解决方案,至于是否支持其他,还得请用过的人来分享一下了。
问个问题:已经在浏览器开启了interceptor,postman中的卫星也打开了,但是在postman的history中没有自动捕获chrome的操作记录。
后方可回复, 如果你还没有账号请点击这里 。
alfredhu (乖乖胡)
第 2200 位会员 /
共收到 3 条回复

我要回帖

更多关于 postman批量测试接口 的文章

 

随机推荐