Postman使用技巧之三:用Postman生成Request代码
来源:互联网 发布:淘宝讲师 编辑:程序博客网 时间:2024/06/07 11:55
Postman这款工具可以让你很方便的测试你的Web API,那如果你实在是没办法用Postman,必须手写代码,又或者你有别的需求是Postman没法实现的,你必须写一个特殊的script或App来测试你的接口,那这时候是不是Postman就没有用武之地了?
我来个你share一个小技巧吧,管不管用你说的算。
假设我现在要这样来测我的接口:
我们要设置用户名和密码:
我们要设置参数和Header:
如果让你写代码来生成这个HTTP Request是不是感觉有点麻烦? 如果你也是个懒人,就打开Postman,配好你想要的HTTP Request,然后点击上图中的Generate Code吧,在弹出的窗口里面,你可以看到这条Request在各种语言里面的对应写法,比如Java OK HTTP:
OkHttpClient client = new OkHttpClient();Request request = new Request.Builder() .url("http://maps.googleapis.com/maps/api/geocode/json?Address=%E4%B8%AD%E5%9B%BD%E5%9B%9B%E5%B7%9D%E6%88%90%E9%83%BD%E5%B8%82%E5%A4%A9%E5%8D%8E%E4%B8%80%E8%B7%AF&sensor=true") .get() .addHeader("accept", "application/xml") .addHeader("cache-control", "no-cache") .addHeader("pragma", "text/cmd") .addHeader("postman-token", "6f00b02c-419f-9b98-f2d3-942ddd1ba081") .build();Response response = client.newCall(request).execute();
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
比如Javascript AJAX:
var settings = { "async": true, "crossDomain": true, "url": "http://maps.googleapis.com/maps/api/geocode/json?Address=%E4%B8%AD%E5%9B%BD%E5%9B%9B%E5%B7%9D%E6%88%90%E9%83%BD%E5%B8%82%E5%A4%A9%E5%8D%8E%E4%B8%80%E8%B7%AF&sensor=true", "method": "GET", "headers": { "accept": "application/xml", "cache-control": "no-cache", "pragma": "text/cmd", "postman-token": "c7d566f4-0e21-9680-e47f-667b3e65280d" }}$.ajax(settings).done(function (response) { console.log(response);});
阅读全文
0 0
- Postman使用技巧之三:用Postman生成Request代码
- Postman使用小技巧 - 用Postman生成Request代码
- Postman使用小技巧
- Postman使用小技巧
- postman使用技巧
- Postman使用技巧之四:pre-request-script和test script
- Postman+Postman interceptor使用
- PostMan 小技巧之-直接使用 chrome 的访问
- postman 使用
- Postman使用
- postman使用
- Postman使用
- postman 使用
- POSTman使用
- postman使用
- Postman
- PostMan
- Postman
- HashSet 的实现原理
- 计数循环的控制
- 模拟实现 memcpy memmove 函数
- leetCode-Search a 2D Matrix
- 每天一个linux命令(35):ln 命令
- Postman使用技巧之三:用Postman生成Request代码
- 每天一个linux命令(36):diff 命令
- C语言趣味一百道 第15道 2017_12_16
- JAVA学习笔记3
- 双线程猜数字
- 每天一个linux命令(37):date命令
- bzoj1070 [SCOI2007]修车
- 每天一个linux命令(38):cal 命令
- 图算法:最短路径之迪杰斯特拉算法