接口一般都有权限的校验,一般是需要登录后才可以调用

对于接口的认证,一般通过两种方式来实现
1、校验用户请求中是否包含某项指定的cookie
2、校验用户的请求的header中是否包含某项指定的字段(token)

案例一:cookie的处理
LR会自动处理cookie,如果需要手动新增cookie,使用web_add_cookie函数
案例二:token的处理
token一般需要手动添加到HTTP信息头中,使用web_add_header函数

先看笔记  token是什么 cookie是什么         https://www.cnblogs.com/zhenyu1/p/10544209.html

  1. Action()
  2. {
  3.  
  4. web_reg_save_param("token",
  5. "LB=data\":\"",
  6. "RB=\"}",
  7. "Ord=1",
  8. LAST);
  9.  
  10. web_custom_request("post", "Method=POST",
  11.  
  12. "URL=http://localhost:8080/pinter/bank/api/login2",
  13.  
  14. "Body=userName=admin&password=1234",
  15.  
  16. "TargetFrame=",
  17.  
  18. LAST );
  19.  
  20. web_add_header("testfan-token","{token}");
  21.  
  22. web_url("query",
  23.  
  24. "URL=http://localhost:8080/pinter/bank/api/query2?userName=admin",
  25.  
  26. LAST );
  27.  
  28. return ;
  29. }

返回日志如下:

log

  1. Virtual User Script started at : -- ::
  2. Starting action vuser_init.
  3. Web Turbo Replay of LoadRunner 11.0. for WINXP; build (Aug ::) [MsgId: MMSG-]
  4. Run Mode: HTML [MsgId: MMSG-]
  5. Run-Time Settings file: "C:\Documents and Settings\test\Local Settings\Temp\noname35\\default.cfg" [MsgId: MMSG-]
  6. Ending action vuser_init.
  7. Running Vuser...
  8. Starting iteration .
  9. Starting action Action.
  10. Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
  11. Action.c(): Notify: Transaction "post_json2" started.
  12. Action.c(): Warning -: The header being added may cause unpredictable results when applied to all ensuing URLs. It is added anyway [MsgId: MWAR-]
  13. Action.c(): web_add_header("Content-type") highest severity level was "warning" [MsgId: MMSG-]
  14. Action.c(): Warning: The string '"userName":"test","password":"1234","gender":1,"phoneNum":"110","email":"beihe@163.com","address":"beijing"' with parameter delimiters is not a parameter.
  15. Action.c(): t=691ms: -byte response headers for "http://localhost:8080/pinter/com/register" (RelFrameId=, Internal ID=)
  16. Action.c(): HTTP/1.1 \r\n
  17. Action.c(): Content-Type: application/json;charset=UTF-\r\n
  18. Action.c(): Transfer-Encoding: chunked\r\n
  19. Action.c(): Date: Sat, Mar :: GMT\r\n
  20. Action.c(): \r\n
  21. Action.c(): t=731ms: -byte chunked response overhead for "http://localhost:8080/pinter/com/register" (RelFrameId=, Internal ID=)
  22. Action.c(): \r\n
  23. Action.c(): t=742ms: -byte chunked response overhead for "http://localhost:8080/pinter/com/register" (RelFrameId=, Internal ID=)
  24. Action.c(): \r\n
  25. Action.c(): \r\n
  26. Action.c(): \r\n
  27. Action.c(): t=783ms: -byte chunked response body for "http://localhost:8080/pinter/com/register" (RelFrameId=, Internal ID=)
  28. Action.c(): {"code":"","message":"娉ㄥ唽鎴愬姛","data":null}
  29. Action.c(): Notify: Saving Parameter "msg = 娉ㄥ唽鎴愬姛".
  30. Action.c(): HTML parsing not performed for Content-Type "application/json" ("ParseHtmlContentType" Run-Time Setting is "TEXT"). URL="http://localhost:8080/pinter/com/register" [MsgId: MMSG-]
  31. Action.c(): web_custom_request("post_json") was successful, body bytes, header bytes, chunking overhead bytes [MsgId: MMSG-]
  32. Action.c(): Notify: Parameter Substitution: parameter "msg" = "娉ㄥ唽鎴愬姛"
  33. Action.c(): Notify: Saving Parameter "sEncoding = 注册成功\x00".
  34. Action.c(): Notify: Parameter Substitution: parameter "sEncoding" = "注册成功\x00"
  35. Action.c(): Notify: Transaction "post_json2" ended with "Pass" status (Duration: 0.7704 Wasted Time: 0.4959).
  36. Ending action Action.
  37. Ending iteration .
  38. Ending Vuser...
  39. Starting action vuser_end.
  40. Ending action vuser_end.
  41. Vuser Terminated.

token接口的测法的更多相关文章

  1. 【token接口】-jmeter

    token 接口 3步骤 1.登录接口 2.提取登录接口的token 3.http 信息管理头   把提取的cookie传入  就可以了

  2. ASP.NET Core WebApi基于Redis实现Token接口安全认证

    一.课程介绍 明人不说暗话,跟着阿笨一起玩WebApi!开发提供数据的WebApi服务,最重要的是数据的安全性.那么对于我们来说,如何确保数据的安全将会是需要思考的问题.在ASP.NET WebSer ...

  3. 接入华为应用内支付,验证购买Token接口,返回“rights invalid”

    有海外开发者向我们提问:我在应用中集成了华为应用内支付SDK(测试购买订阅型商品),按照文档说明,在服务器去请求验证购买Token接口的时候返回了{"responseCode":& ...

  4. 如何区别cookie和token?---测试cookie和token接口时先看。

    cookie 是什么? cookie--------------在浏览器中的长相?火狐浏览器 ----------------------------------------------------- ...

  5. Spring Boot web API接口设计之token、timestamp、sign

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/vbirdbest/article/details/80789817一:token 简介Token:访 ...

  6. 前后端分离之接口登陆权限token

    随着业务的需求普通的springmvc+jsp已经不能满足我们的系统了,会逐渐把后台和前端展示分离开来,下面我们就来把普通的springmvc+jsp分为 springmvc只提供rest接口,前端用 ...

  7. Java生鲜电商平台-API接口设计之token、timestamp、sign 具体设计与实现

    转载:https://www.cnblogs.com/jurendage/p/12653865.html 说明:在实际的业务中,难免会跟第三方系统进行数据的交互与传递,那么如何保证数据在传输过程中的安 ...

  8. Java生鲜电商平台-API接口设计之token、timestamp、sign 具体架构与实现(APP/小程序,传输安全)

    Java生鲜电商平台-API接口设计之token.timestamp.sign 具体设计与实现 说明:在实际的业务中,难免会跟第三方系统进行数据的交互与传递,那么如何保证数据在传输过程中的安全呢(防窃 ...

  9. API接口设计之token、timestamp、sign 具体架构与实现(APP/小程序,传输安全)

    Java生鲜电商平台-API接口设计之token.timestamp.sign 具体设计与实现 说明:在实际的业务中,难免会跟第三方系统进行数据的交互与传递,那么如何保证数据在传输过程中的安全呢(防窃 ...

随机推荐

  1. STM32的备份寄存器和控制状态寄存器

    STM32的备份寄存器和控制状态寄存器 1 备份寄存器用于RTC时钟 RTC时钟可以在掉电以后继续计数,保证时间的延续,但是重新上电以后需要配置,保证之前的计数不会被清除,可以借助备份寄存器实现,备份 ...

  2. Java项目排查cpu负载高

    背景 我负责的其中一个项目在空负载的情况下,CPU占用率依然保持着100%左右,线上.测试.开发的服务都一样:是什么导致的呢?在开发环境我查看了请求流量,这个流量可以忽略但CPU占用率一直在60%-1 ...

  3. YouCompleteMe

    需要配套的.vimrc :sw:.h与.cpp切换 Issue:YouCompleteMe unavailable no module named future cd .vim/Vundle/YouC ...

  4. (Oracle)自定义调用AWR&ADDM

    Oracle->自定义调用AWR&ADDM 需求描述: 前面设定每天自动生成AWR用于提供前一天的数据库状态信息,但因数据库和信息过多不利于直观检查.此次新增ADDM诊断. ADDM诊断 ...

  5. shutil.rmtree()

    shutil.rmtree(path, ignore_errors=False, onerror=None)   #递归地删除文件 def rmtree(path, ignore_errors=Fal ...

  6. Dubbo 安装监控中心

    一.Dubbo 安装服务管理控制台 1.在官方Github下载Dubbo OPS 2.下载incubator-dubbo-ops源码后,解压修改配置文件Zookeeper注册中心地址 3.maven打 ...

  7. wamp 的配置

    一 . 安装  二 . 配置 安装过后打开E:\wamp2\wamp\bin\apache\Apache2.2.21\conf\httpd.conf 寻找Directoy 为文件路径 里面的默认文件删 ...

  8. .Net Core如何在程序的任意位置使用和注入服务

    最近有人问我:我该如何在Startup类之外的地方注入我的服务呢,都写在startup里看着好乱:我该如何在程序的其他地方获取我注入的服务呢: 故我写了这篇博客,文中有不对的地方欢迎指正. 一.如何在 ...

  9. AS5600磁编码器开发记录

    AS5600使用简介--(程序员版) -----------------本文由"智御电子"提供,同时提供范例教程,以便电子爱好者交流学习.---------------- 前言: ...

  10. QWT编译与配置-Windows/Linux环境

    QWT编译与配置-Windows/Linux环境 QWT和FFTW两种开源组件是常用的工程软件支持组件,QWT可以提供丰富的绘图组件功能,FFTW是优秀数字波形分析软件.本文使用基于LGPL版权协议的 ...