惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
The Cloudflare Blog
量子位
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
D
DataBreaches.Net
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 聂微东
有赞技术团队
有赞技术团队
A
About on SuperTechFans

博客园 - JazzieZhang

[转贴] IP 欺骗问题整理 网络始终上不去 郁闷!MSN上不去 QC的数据库恢复 感情生活20条准则【转】 weblogic常见问题 苦苦等待终于有了回报! weblogic调优 打错的电话! 又到一年抗洪时,你还记得他们吗? 老婆要知道,老公要明白 关于三十岁男人的私房话 DB2中几种遇到的SQL1032N出错的解决 转贴,5.30 童年的精彩(70年代~80年代初),以后的就不要看,会羡慕死你们的!^_^ 经典笑话(一) 天元吉弟5月26日 相关报告!^_^ 协议选择问题 使用lrs_save_param时,如何计算偏移量
How to verify download of a file in Web scripts
JazzieZhang · 2007-07-03 · via 博客园 - JazzieZhang

Solution: Perform a text check on part of the binary or output the file to the machine

1. Text check with web_reg_find.
For example, if you have a .pdf file, you can verify the information by using the regular text check function web_reg_find. Replay the script with extended log option "Data returned by server" to help to identify the piece of information to verify. If you decide to check on the text, the information could be in binary format, not as displayed in the Acrobat reader. If this is the case, then you can use the "/BIN" optioin to specify binary data.

2. Check the size of the download.
You can use the web_get_int_property() function with HTTP_INFO_DOWNLOAD_SIZE to check the size of the download is correct.

Example:
long i;

//Start a transaction to download the file.
lr_start_transaction("file_download");

//HTTP call to the .pdf file
web_url("<HTTP call to the pdf file>");

//Get the download size.
i = web_get_int_property( HTTP_INFO_DOWNLOAD_SIZE );

//Check if the size if empty. If so, fail the transaction. You can set it to a specific number if you know the expected size.
if ( i == 0 ){
   //End the transaction
   lr_end_transaction("file_download", LR_FAIL);
   }

else{
   //End the transaction with passed status.
   lr_end_transaction("file_download", LR_PASS);
   }

3. Output the data to a file.
You can also output the data into a file (i.e., download the file, write it to the hard drive), then open it.

Example: (This is for a .pdf file.)
int fp;
long i;

//Truncate to zero length or create file for writing.
fp = fopen("c://my_file.pdf","wb");

//Start a transaction to time the download time.
lr_start_transaction("file_download");

//Set the parameter size large enough to save the data.
web_set_max_html_param_len("100000");

//Use web_reg_save_param with the correct boundary to capture the data returned by the server.
web_reg_save_param("FILED","LB=","RB=","Search=Body",LAST);

//HTTP call to the .pdf file
web_url("<HTTP call to the pdf file>");

//Get the download size.
i = web_get_int_property( HTTP_INFO_DOWNLOAD_SIZE );

//Write the data saved to an output file.
fwrite(lr_eval_string("{FILED}"),i,1,fp);

//End the transaction
lr_end_transaction("file_download", LR_AUTO);

//Close the file pointer.
fclose(fp);