2019独角兽企业重金招聘Python工程师标准>>>
#背景介绍
下载文件是很常见的操作,那么如何用loadrunner实现文件下载呢?
#主要函数
web_url
#Download Script
long fp,Download_Size=0;
float Download_Time=0;
char *data;
unsigned long prmLen;
fp = fopen("c:\\temp\\Introduction.doc","wb");
web_reg_save_param("FILED","LB=","RB=","Search=Body",LAST);
lr_start_transaction("Download_Introduction");
web_url("Introduction",
"URL=http://xx.com/xxx/Doc/Introduction.doc",
"Resource=0",
"RecContentType=text/html, application/xhtml+xml, */*",
"Mode=HTML",
LAST);
lr_output_message("filed : ",lr_eval_string("{FILED}"));
Download_Size= web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
Download_Time= web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);
//Get the download size.
lr_eval_string_ext("{FILED}", strlen("{FILED}"), &data, &prmLen, 0, 0, -1);
//Write the data saved to an output file.
fwrite(data, prmLen, 1, fp);
//Close the file pointer.
fclose(fp);
lr_end_transaction("Download_Introduction,LR_AUTO);
#注意
- URL 请求资源的url地址
- RecContentType 请求资源的类型
下载文件的文件类型可以通过抓包的方式获取,然后在录制选项菜单中 Recording Options ->HTTP Properties ->No-Resources
添加对应的Content-types即可。