NO PAINS,NO GAINS

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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);

posted on 2007-07-03 13:47  JazzieZhang  阅读(373)  评论(0编辑  收藏  举报