loadrunner 通过 cscript 获取js返回值的思路

   
    loadrunner录制脚本后,要增加对挑战的处理,也就是在客户端对用户输入的密码再次加密的过程,加密的一个参数是服务器随机生成的。用户的实际认证是用户名和密码加密后的二次密码与服务器中的用户信息进行比对。 客户端和服务端都用相同的加密算法。
 
    常见的sha256、md5.
 
 loadrunner 的脚本,基本是C语言写的,最优的选择是直接用c实现加密算法。通常web网站应用是js和java的天下,服务器有c++写的。不同的项目,加密的算法略有不同。坦白说,不能用C语言把其他语言实现的算法给翻译过来,最好还是直接引用。
 
有一篇参考文档,把算法实现了,看起来很牛的样子,我试了很多次,主要是败在c语言上。
 
 
 
test.js 文件
 
 
var a = '3';
WScript.Echo a;
 
命令行
 
cscript.exe  test.js //nolog
 
如果要打印结果,直接用管道
echo | cscript.exe  test.js //nolog

这个命令会在命令行中显示a的值。
 
 
 
后续的难点---么搞定:
 
用C语言实现一个函数,
 
第一个是生成一个js文档,因为每次加密的项是从服务器传来的,是变的。用cscript的短处就是不能传参数,无法对js文件传参。那么就每次生成一个新的js文件,
 
第二个就是用c语言获取 命令行执行cscript的返回值,然后用这个值来参数化请求的数据。
 
 
 
 
 
 
@echo off
for /f "tokens=*" %%a in ('cscript test.js //nologo') do (
   echo 处理结果:%%a
)
pause
 
 -----------------------------------------------------------------------------------------------------------------
 
加载动态dll库的参考文章
------------------------------------------------------------------------------------------------------------------

WSCRIPT与CScript区别

窗口中运行,WSCRIPT;命令行中运行,CScrip;
    cscript因为把输出放进了控制台 所以可以对它重定向 方便程序调用
    wscript直接用窗口输出 适合调试程序和编写小工具 在windows下不用cmd的话cscript的输出会一闪而过 大多数情况下,列在下表中的选项适用于 WScript.exe 和 CScript.exe。例外情况会加以注释。

参数                      说明
//B                       批处理模式;隐藏用户提示和脚本错误在命令行中的显示。默认模式是交互模式。
//D                       打开调试程序。
//E:engine                用指定的脚本引擎执行脚本。
//H:CScript或 //H:Wscript 将 CScript.exe 或 WScript.exe 注册为运行脚本的默认应用程序。如果未指定,则将 WScript.exe 假设为默认应用程序。
//I                       默认。交互模式;允许显示用户提示和脚本错误。与批处理模式相反。
//Job:<JobID>             从 .wsf 文件运行指定的 JobID。
//logo                    默认。显示标题。与 nologo 相反。
//nologo                  防止在运行时显示执行标题。默认设置是 logo。
//S                       保存该用户的当前命令行选项。
//T:nn                    启用超时:脚本可以运行的最大秒数。默认设置是无限制。//T 参数通过设置定时器来防止脚本执行过度。当执行时间超过指定值时,CScript 用 IActiveScript::InterruptThread 方法中断脚本引擎,并终止过程。
//U                       用于 Windows NT 和 Windows 2000,强制命令行以 Unicode 格式输出。CScript 无法决定以 Unicode 还是以 ANSI 输出;默认设置为 ANSI。
//X                       在调试程序中启动该程序。
//?    

 

Script Hosts
The script host initiates and coordinates the running of your script; it reads your script file and interacts with components of the WSH environment and any COM objects required by the script. It is also the responsibility of the script host to determine which language engine to use when running the script. For example, if the script has a .vbs extension, the script host will load the VBScript language engine and begin working with that engine to execute the code.

The WSH environment includes two script hosts: the console-based CScript and the GUI-based WScript. The two script hosts provide nearly identical capabilities, and in most cases, it does not matter which of the script hosts you use to run your scripts.

The two exceptions lie in how you interact with a script; that is, how you get information into a script (input) and how the script displays information it has retrieved (output). In general, CScript receives input from the command prompt and displays output in a command window. WScript, by contrast, receives input through a graphical dialog box and displays output in a graphical message box.

Otherwise, the two script hosts are largely identical: If you have a script that does not require user interaction, you can run that script under either CScript or WScript. For example, the following script maps a network drive. Because it neither requires input nor displays output, it runs exactly the same under either script host:

Set objNetwork = Wscript.CreateObject("WScript.Network")objNetwork.MapNetworkDrive "g:", "\\atl-fs-01\Sales"
On the other hand, the following script which displays a series of messages runs much differently under CScript (where the messages are displayed as individual lines within a command window) and WScript (where the messages are displayed as a series of message boxes). If you are interested in seeing the difference for yourself, copy the script into Notepad, save it with a .vbs file extension, and then run it under both CScript and WScript. (For more information about running scripts under a script host, see "Running WSH Scripts" later in this chapter.)

复制代码 代码如下:

Wscript.Echo "Line 1."
Wscript.Echo "Line 2."
Wscript.Echo "Line 3."
Wscript.Echo "Line 4."
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值