需求:10個客戶並發下載同一份zip文件。
執行的時候,8個Fail了,只下載了兩份zip,且無論執行多少遍,都是這樣。
錯誤信息如下:
message code:-19890
C interpreter run time error: memory violation:exception access_violation received
網上各種解決辦法都試過,無效,通過排除法,對腳本一點點注釋、執行,最終發現導致本錯誤的根本原因是:
web_set_max_html_param_len("10240000");這一句中指定的長度太大了,而我要下載的文件只有4k,改成4096000后,問題解決。
Action() { int flen; longfiledes; char filename1[50]; charfilename[50]; charfilepath[50]; char *fileSuffix; lr_save_datetime("%Y%m%d%H%M%S",DATE_NOW,"now"); fileSuffix = lr_eval_string("{num}"); sprintf(filename,"%s%d.rar",lr_eval_string("{now}"),fileSuffix); lr_save_string(filename,"filename1"); strcpy(filepath,"D:\\test\\download\\"); strcat(filepath,lr_eval_string("{filename1}")); lr_message("%s",filepath); web_set_max_html_param_len("10240000"); web_reg_save_param("fcontent","LB=", "RB=", "SEARCH=BODY", LAST); lr_rendezvous("並發"); lr_start_transaction("download"); web_url("attachment.aspx", "URL=http://172.0.0.1:8081/package/2015wwerwt34w553qq.zip", "TargetFrame=","Resource=0", "RecContentType=application/zip", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST); lr_end_transaction("download",LR_AUTO); flen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); if(flen> 0) { //以寫方式打開文件 if((filedes = fopen(filepath,"wb")) == NULL) { lr_output_message("Open File Failed!"); return -1; } //寫入文件內容 fwrite(lr_eval_string("{fcontent}"),flen, 1, filedes); //關閉文件 fclose(filedes); } return 0; }