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的例子来好了。