LoadRunner獲取接口請求響應信息
參數說明
1、REQUEST,用於提取完整的請求頭信息。
2、RESPONSE,用於提取完整的響應頭信息。
3、ResponseBody ,用於提取完整的響應體信息。
注意,這兩個變量僅在請求前使用web_save_header註冊使用。示例如下:
Action()
{
// 默認最大長度爲256
web_set_max_html_param_len("262144");
//自定義截取字符串,根據左右字符串獲取數據
web_reg_save_param("ResponseBody",
"LB=", "RB=", "Search=Body", LAST);
// REQUEST爲內置變量,保存請求的頭信息,需在發送URL請求前註冊使用,將請求頭信息存入字符串RequestHeader中
web_save_header(REQUEST,
"RequestHeader");
// 將RESPONSE保存響應的頭信息在字符串ResponseHeader中
web_save_header(RESPONSE,
"ResponseHeader");
web_url("blog",
"URL=http://blog.sina.com.cn/bestfeiyong",
"Resource=0",
"RecContentType=text/html",
"Mode=HTTP",
LAST);
//字符轉碼
lr_convert_string_encoding(lr_eval_string("{RequestHeader}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"RequestHeaderUTF8");
lr_convert_string_encoding(lr_eval_string("{ResponseHeader}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"ResponseHeaderUTF8");
lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"ResponseBodyUTF8");
//輸出信息
lr_output_message("# 請求頭信息:\n %s", lr_eval_string("{RequestHeaderUTF8}"));
lr_output_message("# 響應頭信息:\n %s", lr_eval_string("{ResponseHeaderUTF8}"));
lr_output_message("# 響應內容體:\n %s", lr_eval_string("{ResponseBodyUTF8}"));
return 0;
}
輸出:
Action.c(19): # 請求頭信息:
GET /bestfeiyong HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT)
Accept-Encoding: gzip, deflate
Accept: */*
Connection: Keep-Alive
Host: blog.sina.com.cn
Action.c(20): # 響應頭信息:
HTTP/1.1 200 OK
Server: nginx/1.0.8
Date: Mon, 30 Jul 2012 02:49:19 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
Cache-Control: no-cache
Expires: Mon, 30 Jul 2012 02:49:18 GMT
Last-Modified: Mon, 30 Jul 2012 10:45:10 GMT+8
DPOOL_HEADER: 10.55.27.46
Age: 249
X-Cache: HIT from sh-223-36.squid.blog.sina.com.cn
X-debug: 114.80.223.58
Content-Encoding: gzip
請求體略....
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.