一、 上传脚本
Action()
{
int uploadImgStatus = 0;
//获取上传产品图ID
web_reg_save_param_ex("ParamName=imgRandName",
"LB=\"sourceImgPath\":\"upload\\/cropzoomimg\\/",
"RB=\"}",
LAST);
uploadImgStatus = web_submit_data("CropZoomImgController.do",
"Action=http://192.168.2.67:7001/CropZoomImgController.do?method=uploadSourceImg",
"Method=POST",
"EncType=multipart/form-data",
"Referer=http://192.168.2.67:7001/GoodsController.do?method=toCreateGoods",
"Snapshot=t377.inf",
"Mode=HTTP",
ITEMDATA,
"Name=attachFile", "Value=G:\\123.txt", "File=Yes", ENDITEM,
LAST);
if (uploadImgStatus == 1) {
//如果上传失败则终止脚本
lr_abort();
lr_error_message("上传失败!");
} else {
//输出上传图片ID(调试使用)
lr_output_message("%s", lr_eval_string("{imgRandName}"));
}
return 0;
}
二、下载脚本
Action()
{ //定义一个整型变量保存获得文件的大小int flen; //保存文件句柄long filedes; //保存文件路径及文件名char file[256]="\0"; char * chNumber ;int time;//设置页面接收最大的字节数,该设置应大于下载文件的大小web_set_max_html_param_len("1024000"); //并发开始web_concurrent_start(NULL);//使用关联函数获取下载文件的内容web_reg_save_param("filecontent","LB=","RB=","Search=BODY",LAST); web_url("android.apk",//下载链接"URL=http://res.t.ifeng.com/download/android/ifeng_weibo_android_v1.01beta.apk","Resource=1","RecContentType=application/force-download","Referer=",LAST); //并发结束web_concurrent_end(NULL); //获得下载文件大小flen =web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); time=web_get_int_property (HTTP_INFO_DOWNLOAD_TIME);lr_output_message("下载时间是%d",time);//生成随机数chNumber=lr_eval_string("{NewParam}"); //将下载文件要保存的路径存到file里strcat(file,"F:\\file");//在文件名后自动生成随机数strcat(file,chNumber);//下载的文件后缀名称strcat(file,".apk");if(flen > 0){ if((filedes = fopen(file,"wb")) == NULL){ lr_output_message("Open FileFailed!", lr_eval_string("{filecontent}"));return -1;}fwrite(lr_eval_string("{filecontent}"),flen,1,filedes );fclose( filedes );}return 0;}