1.概述:LR得到了服务器响应的文件内容(日志中的那些乱码),但无法记录文件如何保存到本地。我们把这个请求写在一个单独的action中,通过关联可以把服务器响应的文件内容获取下来再写到本地便完成了下载文件的保存
2.原有文件名:
init(){ ... }
Action()
{
char FilePath[256]="\0"; //文件名称
int flen; //文件长度
long fileds; //文件句柄
web_set_max_html_param_len("10000"); //页面接受的最大字节数,应大于下载文件的大小
web_reg_save_param
("FileName", "LB=filename=\"", "RB=\", "Search=all", LAST);
//关联文件名(常量文件名无需关联)
web_reg_save_param("FileContent", "LB=", "RB=", "Search=BODY", LAST);
//关联下载文件内容
web_url("download.php","URL=http://211.147.208.141/cn/resources/download.php?id=386","Resource=1","RecContentType=application/force-download","Referer=",LAST); //发出下载请求
strcat(FilePath, "c:\\");
strcat(FilePath, lr_eval_string("{FileName}"));
flen=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); //获得文件长度
if(flen > 0)
{ if((fileds=fopen(FilePath,"wb"))==NULL) //获得文件句柄
{lr_output_message("Open File Failed"); return -1;}
fwrite(lr_eval_string("{FileContent}"), flen, 1, fileds);
fclose(fileds);
}
return 0;
}
3.随机文件名:
init(){ ... }
Action()
{
char FilePath[256]="\0";
char *FileName=lr_eval_string("{NewParam}"); //Random Number
int flen;
long fields;
web_set_max_html_param_len("10000");
web_reg_save_param("FileContent", "LB=", "RB=", "Search=BODY", LAST);
web_url("%E6%88%90%E9%BE%99%20-%20%E5%A3%AE%E5%BF%97%E5%9C%A8%E6%88%91%E8%83%B8.wma","URL=http://down.wz500.com/MP3%E4%B8%8B%E8%BD%BD/%E6%B5%81%E8%A1%8C%E6%AD%8C%E6%9B%B2800%E9%A6%96/%E6%88%90%
E9%BE%99%20-%20%E5%A3%AE%E5%BF%97%E5%9C%A8%E6%88%91%E8%83%B8.wma","Resource=1","RecContentType=audio/x-ms-wma","Referer=","Snapshot=t4.inf",LAST);
strcat(FilePath, "D:\\");
strcat(FilePath, FileName);
strcat(FilePath, ".wma");
flen=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
if(flen > 0)
{ if((fields=fopen(FilePath, "wb"))==NULL)
{lr_output_message("Open Failed"); return -1;}
fwrite(lr_eval_string("{FileContent}"), flen, 1, fields);
fclose(fields);
}
return 0;
}