|
最近有人看了我的Google的ajax案例后想做个baidu的,然后总是做不出来于是问我,这里丢一个Baidu Ajax的Loadrunner 9.52的代码,其实道理是一样的,虽然代码不一样,写不出来我觉得还是基础不够扎实而已。
ajax到底是什么,就是小片段发http请求返回数据包再更新本页而已,baidu的ajax只是在编码上采用了json的方式,LR解包要做2次分离而已。
代码如下:
splitchartoparamarr(char *x,char *y,char *paramarrname)//该函数的作用是输入*x,按照*y边界进行分割,最后生成参数数组paramarrname
{
extern char * strtok(char * string, const char * delimiters );
char charstring[1000],separators[100],paramname[110];//定义输入的字符串,分割符和需要生成的数组名,字符串长度1000,分隔符100,数组名100
char * token;
int i=0;//初始化计数器
char paramcount[10],paramarrcount[110];//定义生成参数数组的两个元素,参数数组长度及参数数组名_count参数
strcpy(charstring,x);
strcpy(separators,y);
token = (char *)strtok(charstring, separators); // Get the first token
if (!token) {
lr_output_message ("No tokens found in string!");
return( -1 );
}
while (token != NULL ) { // While valid tokens are returned
//lr_output_message ("%s", token );//输出分割内容
i++;
sprintf(paramname,"%s_%d",paramarrname,i);
//lr_output_message ("%s", paramname );//输出参数名
lr_save_string(token,paramname);
token = (char *)strtok(NULL, separators); // Get the next token
}
sprintf(paramarrcount,"%s_count",paramarrname);
itoa(i,paramcount,10);
lr_save_string(paramcount,paramarrcount);
}
Action()
{
web_add_cookie("BAIDUID=E7D926225049FBFA2825D275471717A8:FG=1; DOMAIN=www.baidu.com");
web_url("www.baidu.com",
"URL=http://www.baidu.com/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t16.inf",
"Mode=HTML",
EXTRARES,
"Url=/js/bdsug.js?v=1.0.3.0", ENDITEM,
"Url=/favicon.ico", "Referer=", ENDITEM,
LAST);
web_add_cookie("BAIDUID=E7D926225049FBFA2825D275471717A8:FG=1; DOMAIN=suggestion.baidu.com");
lr_think_time(13);
web_url("su",
"URL=http://suggestion.baidu.com/su?wd=l&p=3&cb=window.bdsug.sug&t=1284106978040",
"TargetFrame=",
"Resource=0",
"RecContentType=baiduapp/json",
"Referer=http://www.baidu.com/",
"Snapshot=t17.inf",
"Mode=HTML",
LAST);
web_url("su_2",
"URL=http://suggestion.baidu.com/su?wd=load&p=3&cb=window.bdsug.sug&t=1284106978427",
"TargetFrame=",
"Resource=0",
"RecContentType=baiduapp/json",
"Referer=http://www.baidu.com/",
"Snapshot=t18.inf",
"Mode=HTML",
LAST);
web_url("su_3",
"URL=http://suggestion.baidu.com/su?wd=loadu&p=3&cb=window.bdsug.sug&t=1284106978662",
"TargetFrame=",
"Resource=0",
"RecContentType=baiduapp/json",
"Referer=http://www.baidu.com/",
"Snapshot=t19.inf",
"Mode=HTML",
LAST);
web_url("su_4",
"URL=http://suggestion.baidu.com/su?wd=loadr&p=3&cb=window.bdsug.sug&t=1284106979097",
"TargetFrame=",
"Resource=0",
"RecContentType=baiduapp/json",
"Referer=http://www.baidu.com/",
"Snapshot=t20.inf",
"Mode=HTML",
LAST);
web_url("su_5",
"URL=http://suggestion.baidu.com/su?wd=loadru&p=3&cb=window.bdsug.sug&t=1284106979222",
"TargetFrame=",
"Resource=0",
"RecContentType=baiduapp/json",
"Referer=http://www.baidu.com/",
"Snapshot=t21.inf",
"Mode=HTML",
LAST);
web_url("su_6",
"URL=http://suggestion.baidu.com/su?wd=loadrun&p=3&cb=window.bdsug.sug&t=1284106979396",
"TargetFrame=",
"Resource=0",
"RecContentType=baiduapp/json",
"Referer=http://www.baidu.com/",
"Snapshot=t22.inf",
"Mode=HTML",
LAST);
web_reg_save_param("search",
"LB=[\"",
"RB=\"]",
"Ord=1",
"Search=NoResource",
LAST);
web_url("su_7",
"URL=http://suggestion.baidu.com/su?wd=loadrunner&p=3&cb=window.bdsug.sug&t=1284106979773",
"TargetFrame=",
"Resource=0",
"RecContentType=baiduapp/json",
"Referer=http://www.baidu.com/",
"Snapshot=t23.inf",
"Mode=HTML",
LAST);
splitchartoparamarr(lr_eval_string("{search}"),"\",\"","ajaxsearch");
lr_save_string(lr_paramarr_random("ajaxsearch"),"temp");
web_add_cookie("BAIDUID=E7D926225049FBFA2825D275471717A8:FG=1; DOMAIN=s.baidu.com");
web_url("s",
"URL=http://www.baidu.com/s?wd={temp}&oq=loadrunner&rsp=2&f=3&sugT=3295",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://www.baidu.com/",
"Snapshot=t24.inf",
"Mode=HTML",
EXTRARES,
"Url=http://s.baidu.com/w.gif?q=loadrunner+9%2E5+%C6%C6%BD%E2&fm=se&T=1284106991&y=8EDEAABA&cw=1379&path=http://www.baidu.com/s?wd=loadrunner+9.5+%C6%C6%BD%E2&oq=loadrunner&rsp=2&f=3&sugT=3295&cid=0&qid=df03299c01c602f8&t=1284106982379", "Referer=http://www.baidu.com/s?wd=loadrunner+9.5+%C6%C6%BD%E2&oq=loadrunner&rsp=2&f=3&sugT=3295", ENDITEM,
LAST);
return 0;
} |
|