LoadRunner性能测试-下载文件脚本

Action()
{
         intflen;   //定义一个整型变量保存获得文件的大小
         longfiledes; //保存文件句柄
         charfile[256]="\0"; //保存文件路径及文件名
         inttime ;
 
//设置页面接收最大的字节数,该设置应大于下载文件的大小,此处为1MB
         web_set_max_html_param_len("1024000");
 
//使用关联函数获取下载文件的内容
         web_reg_save_param_ex(      
                      "ParamName=filecontent",
                      "LB=",
                      "RB=",
                       SEARCH_FILTERS,
                      "Scope=Body",    
"RequestUrl=http://10.255.0.145/download.php?userId={userID}&bigmd5={userID}&offset=0",
         LAST);
 
  //下载文件
         lr_start_transaction("download");
         web_url("download",       
           "URL=http://10.255.0.145/download.php?userId={userID}&bigmd5={userID}&offset=0",
                   Resource=1",           
                   "RecContentType=application/octet-stream",
                   "Referer=",
         LAST);
         lr_end_transaction("download",LR_AUTO);
 
/*web_get_int_property返回上一个http请求的具体信息,如HTTP_INFO_DOWNLOAD_SIZE, HTTP_INFO_DOWNLOAD_TIME , HTTP_INFO_RETURN_CODE */
 
                 flen=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);     
                 lr_output_message("下载文件大小是:%d",flen);
                 time=web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);
                 lr_output_message("下载时间是:%d",time);
                  
                 //把“E:\\FSDownload\\%d.txt”这个字符串写到file中
                 sprintf(file,"E:\\FSDownload\\%d.txt",rand());
                 lr_output_message("保存的路径:%s",file);
 
               if(flen> 0){
                 if((filedes= fopen(file,"wb")) == NULL){
                    lr_output_message("OpenFile Failed!", lr_eval_string("{filecontent}"));
                                     return-1;
                  }
                  
                //把filecontent写到filedes指针指向的文件中,每次写flen,写1次
                fwrite(lr_eval_string("{filecontent}"),flen,1,filedes);
                fclose(filedes );
              }
         return0;
}

 

转载于:https://www.cnblogs.com/yunman/p/7888867.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值