LoadRunner下载文件

Action()
{
    int filelen=0;
    int filebody=0;
    char filename[1024];

    web_reg_find("Text=HTTP/1.1 200 OK",
                 "SaveCount=count",
                 "Search=all",
                 LAST);

    web_reg_save_param("url",
       "LB={\"Result\":\"",
       "RB==",
       "SEARCH=ALL",
       LAST );

    lr_rendezvous("素材资源下载");

    lr_start_transaction("素材资源下载");

    lr_think_time(10);

    web_url("GetWebResource",
        "URL=http://1##:8087/TMV3DSource/GetWebResource?SourceID={SourceID}",
        //"URL=http://1##:8087/TMV3DSource/GetWebResource?SourceID=111",
        "Resource=1",
        "RecContentType=application/json",
        "Referer=",
        "Snapshot=t1.inf",
        LAST);

    web_set_max_html_param_len("20000");

    web_reg_save_param("file_value",
       "LB=",
       "RB=",
       "SEARCH=BODY",
       LAST );

    web_url("url",
        "URL={url}",
        "Resource=1",
        "RecContentType=application/msword",
        "Referer=",
        "Snapshot=t2.inf",
        LAST);

    filelen=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
    strcpy(filename,"F:/file_name/");
    strcat(filename,lr_eval_string("{local_filename_num}"));
    strcat(filename,".doc");

    //strcat(filename,lr_eval_string("{url}"));


    if(filelen>0)
    {
        if((filebody=fopen(filename,"wb"))==NULL)
        {
            lr_error_message("文件打开失败");
            return -1;
        }
    }

    fwrite(lr_eval_string("{file_value}"),filelen,1,filebody);
    fclose(filebody);
    free(filebody);
    

    if(atoi(lr_eval_string("{count}"))>0)
        lr_end_transaction("素材资源下载", LR_PASS);
    else
        lr_end_transaction("素材资源下载", LR_FAIL);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xuyubotest/article/details/46692901