Action()
{
/*总要求:
1.页面存在2条以上票务信息,则随机退2张票,若只有1条票务信息,则退1张票;如果没票可退,直接退出.
使用web_custom_request模拟请求;
主要问题:没票直接退出,但是会出现找不到参数的问题,需要勾选Run-time Setting-Miscellaneous-Continue on error*/
int i,len,r1,r2;
char *Body;//最终拼接
char r1_temp[64];
char r2_temp[64];
char cgifields[32];
Body=(char *)malloc(10000*sizeof(char));
srand((unsigned)time(NULL));
web_set_max_html_param_len("204800");
/*参数化所有flightID:name="flightID" value="1845222-15462-44"*/
web_reg_save_param("f_ID",
"LB=name="flightID" value="",
"RB="",
"Ord=All",
"NotFound=ERROR",
"Search=Body",
LAST);
web_reg_find("Search=All",
"SaveCount=count",
"Text=A total of ",
LAST);
lr_start_transaction("退票");
web_url("Itinerary Button",
"URL={url}welcome.pl?page=itinerary",
"TargetFrame=body",
"Resource=0",
"RecContentType=text/html",
"Referer={url}nav.pl?page=menu&in=home",
"Snapshot=t6.inf",
"Mode=HTML",
LAST);
if(atoi(lr_eval_string("{count}"))!=0){
strcpy(Body,"Body=");
len=lr_paramarr_len("f_ID");
lr_output_message("机票数目长度:%d",len);
do{//生成2个不同的随机数
r1=rand()%len+1;
r2=rand()%len+1;
}while(r1==r2);
lr_output_message("随机删除机票:%d,%d",r1,r2);
for(i=1;i<=len;i++){
if(len>=2){//存在2条以上票务信息,则随机退2张票
if(r1==i){
strcat(Body,itoa(r1, r1_temp, 10));
strcat(Body,"=on&");
}
if(r2==i){
strcat(Body,itoa(r2, r2_temp, 10));
strcat(Body,"=on&");
}
}
if(len==1){//只有1条票务信息,则退1张票;
strcat(Body,"1=on&");
}
strcat(Body,"flightID=");
strcat(Body,lr_paramarr_idx("f_ID",i));
strcat(Body,"&");
}
for(i=1;i<=len;i++){
sprintf(cgifields,".cgifields=%d%s",i,"&");
strcat(Body,cgifields);
}
strcat(Body,"removeFlights.x=79&removeFlights.y=10");
lr_output_message("%s",Body);
web_custom_request ("itinerary.pl_2",
"URL={url}itinerary.pl",
"Method=POST",
Body,
LAST);
lr_end_transaction("退票",LR_AUTO);
}else{
lr_start_transaction("退出");
web_url("SignOff Button",
"URL={url}welcome.pl?signOff=1",
"TargetFrame=body",
"Resource=0",
"RecContentType=text/html",
"Referer={url}nav.pl?page=menu&in=itinerary",
"Snapshot=t7.inf",
"Mode=HTML",
LAST);
lr_end_transaction("退出",LR_AUTO);
}
return 0;
}