loadrunner 获取http head参数方法
2010-12-22 16:20
423 查看
1、首先获取http response的整个头的内容
这里其实我也google而来的。
2、就是解析这个字符串了。不知道有没有其他直接获取这些value的方法。
脚本如下:
Action()
{
web_set_max_html_param_len("262144");
web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST);//响应的body
web_save_header(REQUEST, "RequestHeader");//请求的头
web_save_header(RESPONSE, "ResponseHeader");//响应的头
web_url("auth",
"URL=http://10.250.3.52:8008/data/",
"Resource=0",
"RecContentType=text/html",
"Mode=HTTP",
LAST);
//下面都是对这个字符串的处理了~~用c真他妈的麻烦,python2行代码可以搞定的,c就要搞死了。
digest = lr_eval_string("{ResponseHeader}");
lr_output_message("response is :%s",digest);
realm=(char *)getValue(digest,"realm");
qop = (char *)getValue(digest,"qop");
nonce = (char *)getValue(digest,"nonce");
opaque = (char *)getValue(digest,"opaque");
lr_output_message("realm is:%s",realm);
lr_output_message("qop is:%s",qop);
lr_output_message("nonce is:%s",nonce);
lr_output_message("opaque is:%s",opaque);
return 0;
}
getValue函数
char * getValue(char *source,char *key){
tmp2 = (char *)malloc(64);
memset(tmp2,0,64);
tmp = (char *)strstr(source,key);
tmp = tmp + (strlen(key))+2;//因为还有个=号,所以要加2
tmp1 = (char *)strchr(tmp,'/"');
length = tmp1-tmp;//获取value的长度
for (i = 0;i<length;i++) {
sprintf(tmp2,"%s%c",tmp2,tmp[i]);
}
return tmp2;
}
运行结果:
Action.c(16): response is :HTTP/1.1 401 Unauthorized
Server: nginx/0.8.50
Date: Wed, 22 Dec 2010 08:09:29 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
WWW-Authenticate: Digest realm="aliuid",qop="auth",nonce="b7e2329d98b791415258e33e99274ffcf6",opaque="4dd61bf64b37861d12bb9f46bdba9f19"
Action.c(21): realm is:aliuid
Action.c(22): qop is:auth
Action.c(23): nonce is:b7e2329d98b791415258e33e99274ffcf6
Action.c(24): opaque is:4dd61bf64b37861d12bb9f46bdba9f19
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
ps:设置head的函数:web_add_header("Authorization","{authstring}");
比较简单,按照f1的例子来好了。
这里其实我也google而来的。
2、就是解析这个字符串了。不知道有没有其他直接获取这些value的方法。
脚本如下:
Action()
{
web_set_max_html_param_len("262144");
web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST);//响应的body
web_save_header(REQUEST, "RequestHeader");//请求的头
web_save_header(RESPONSE, "ResponseHeader");//响应的头
web_url("auth",
"URL=http://10.250.3.52:8008/data/",
"Resource=0",
"RecContentType=text/html",
"Mode=HTTP",
LAST);
//下面都是对这个字符串的处理了~~用c真他妈的麻烦,python2行代码可以搞定的,c就要搞死了。
digest = lr_eval_string("{ResponseHeader}");
lr_output_message("response is :%s",digest);
realm=(char *)getValue(digest,"realm");
qop = (char *)getValue(digest,"qop");
nonce = (char *)getValue(digest,"nonce");
opaque = (char *)getValue(digest,"opaque");
lr_output_message("realm is:%s",realm);
lr_output_message("qop is:%s",qop);
lr_output_message("nonce is:%s",nonce);
lr_output_message("opaque is:%s",opaque);
return 0;
}
getValue函数
char * getValue(char *source,char *key){
tmp2 = (char *)malloc(64);
memset(tmp2,0,64);
tmp = (char *)strstr(source,key);
tmp = tmp + (strlen(key))+2;//因为还有个=号,所以要加2
tmp1 = (char *)strchr(tmp,'/"');
length = tmp1-tmp;//获取value的长度
for (i = 0;i<length;i++) {
sprintf(tmp2,"%s%c",tmp2,tmp[i]);
}
return tmp2;
}
运行结果:
Action.c(16): response is :HTTP/1.1 401 Unauthorized
Server: nginx/0.8.50
Date: Wed, 22 Dec 2010 08:09:29 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
WWW-Authenticate: Digest realm="aliuid",qop="auth",nonce="b7e2329d98b791415258e33e99274ffcf6",opaque="4dd61bf64b37861d12bb9f46bdba9f19"
Action.c(21): realm is:aliuid
Action.c(22): qop is:auth
Action.c(23): nonce is:b7e2329d98b791415258e33e99274ffcf6
Action.c(24): opaque is:4dd61bf64b37861d12bb9f46bdba9f19
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
ps:设置head的函数:web_add_header("Authorization","{authstring}");
比较简单,按照f1的例子来好了。
相关文章推荐
- http获取输入流输出流的参数及方法
- Flex中HTTPService请求参数中存在中文,后台获取为乱码的解决方法
- loadrunner获取Http信息头中指定值作为参数
- Action中获取HttpServletRequest对象的方法(表单提交值,url传递参数)
- struts2 Interceptor(拦截器)中获取HTTP 参数的方法
- jquery 获取HTTP后的参数方法
- [c#美味]使用Http Head方法获取文件长度
- HTTP head 方法(介绍一些参数的意义)
- AngularJS出现$http异步后台无法获取请求参数问题的解决方法
- 使用Http Head方法获取文件长度
- SpringMVC Ajax 获取参数的方法
- jsp 页面获取request参数方法
- javascript获取src参数方法——转载
- Java Spring Controller 获取请求参数的几种方法详解
- Servlet获取AJAX POST请求中参数以form data和request payload形式传输的方法
- php cli模式下获取参数的方法
- SPRING MVC 的请求参数获取的几种方法
- AspectJ 切面获取方法参数并拿到具体的值
- JS获取URL参数方法