zoukankan      html  css  js  c++  java
  • Loadrunner上传与下载文件脚本

    一、 上传脚本

    Action()

    {

    int uploadImgStatus = 0;

      //获取上传产品图ID

    web_reg_save_param_ex("ParamName=imgRandName",

    "LB="sourceImgPath":"upload\/cropzoomimg\/",

    "RB="}",

    LAST);

    uploadImgStatus = web_submit_data("CropZoomImgController.do",

    "Action=http://192.168.2.67:7001/CropZoomImgController.do?method=uploadSourceImg",

    "Method=POST",

    "EncType=multipart/form-data",

    "Referer=http://192.168.2.67:7001/GoodsController.do?method=toCreateGoods",

    "Snapshot=t377.inf",

    "Mode=HTTP",

    ITEMDATA,

    "Name=attachFile", "Value=G:\123.txt", "File=Yes", ENDITEM,

    LAST);

    if (uploadImgStatus == 1) {

      //如果上传失败则终止脚本

    lr_abort();

    lr_error_message("上传失败!");

    } else {

       //输出上传图片ID(调试使用)

    lr_output_message("%s", lr_eval_string("{imgRandName}"));

    }

    return 0;

    }

    二、下载脚本

    Action()

    {

    //定义一个整型变量保存获得文件的大小
    int flen; 

    //保存文件句柄
    long filedes; 

    //保存文件路径及文件名
    char file[256]=""; 

    char * chNumber ;

    int time;

    //设置页面接收最大的字节数,该设置应大于下载文件的大小
    web_set_max_html_param_len("1024000"); 

    //并发开始
    web_concurrent_start(NULL);

    //使用关联函数获取下载文件的内容
    web_reg_save_param("filecontent",

    "LB=",

    "RB=",

    "Search=BODY",

    LAST); 

    web_url("android.apk",

    //下载链接
    "URL=http://res.t.ifeng.com/download/android/ifeng_weibo_android_v1.01beta.apk",

    "Resource=1",

    "RecContentType=application/force-download",

    "Referer=",

    LAST);


    //并发结束
    web_concurrent_end(NULL); 


    //获得下载文件大小
    flen =web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); 

    time=web_get_int_property (HTTP_INFO_DOWNLOAD_TIME);

    lr_output_message("下载时间是%d",time);


    //生成随机数
    chNumber=lr_eval_string("{NewParam}"); 


    //将下载文件要保存的路径存到file里
    strcat(file,"F:\file");

    //在文件名后自动生成随机数
    strcat(file,chNumber);

    //下载的文件后缀名称
    strcat(file,".apk");

    if(flen > 0)

    {

    if((filedes = fopen(file,"wb")) == NULL)

    {

    lr_output_message("Open FileFailed!", lr_eval_string("{filecontent}"));

    return -1;

    }

    fwrite(lr_eval_string("{filecontent}"),flen,1,filedes );

    fclose( filedes );

    }

    return 0;

    }

  • 相关阅读:
    【基础算法】- 全排列
    【基础算法】- 2分查找
    区块链培训
    Static Binding (Early Binding) vs Dynamic Binding (Late Binding)
    test
    No data is deployed on the contract address!
    "throw" is deprecated in favour of "revert()", "require()" and "assert()".
    Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
    京都行
    Failed to write genesis block: database already contains an incompatible
  • 原文地址:https://www.cnblogs.com/HCT118/p/5276857.html
Copyright © 2011-2022 走看看