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


    Action()
    {
             intflen;   //定义一个整型变量保存获得文件的大小
             longfiledes; //保存文件句柄
             charfile[256]=""; //保存文件路径及文件名
             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;
    }
  • 相关阅读:
    java对redis的基本操作(一)
    Android RelativeLayout 属性
    查看jdk的位数
    Java简单文件传输 socket简单文件传输示例
    Java使用socket实现两人聊天对话
    Java观察者设计模式
    Java装饰设计模式的例子
    php邮件发送 phpmailer
    php smarty 缓存和配置文件的基本使用方法
    php smarty insert用法
  • 原文地址:https://www.cnblogs.com/yunman/p/7888867.html
Copyright © 2020-2023  润新知