- <span style="font-size:18px;">Action()
- {
- int nHttpRetCode;
- web_set_max_html_param_len("262144"); // 默认最大长度为256
- web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST);
- web_save_header(RESPONSE,"ResponseHeader");
- lr_start_transaction("Communicate");
- web_custom_request("getname",
- "URL=http://www.baidu.com",
- "Method=GET",
- "Resource=0",
- "Referer=",
- "Mode=HTTP",
- "EncType=text/html;charset=UTF-8",
- "Body=",
- LAST);
- //UTF-8转换到本地编码
- //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("{ResponseHeaderUTF8}"));
- //lr_output_message("# 响应内容体:\n %s", lr_eval_string("{ResponseBodyUTF8}"));
- //打印返回信息
- lr_output_message("# 响应头信息:\n %s", lr_eval_string("{ResponseHeader}"));
- lr_output_message("# 响应内容体:\n %s", lr_eval_string("{ResponseBody}"));
- lr_end_transaction("Communicate", LR_PASS);
- nHttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE);
- if(nHttpRetCode == 200)
- {
- lr_output_message("---------------Success!------------");
- }
- else
- {
- lr_output_message("----------------Failed!------------");
- }
- return 0;
- }
- </span>
在LoadRunner中,为提供了一个字符串编码转换的函数
int lr_convert_string_encoding ( const char *sourceString, const char *fromEncoding, const char *toEncoding, const char *paramName);
该函数有4个参数,含义如下:
sourceString:被转换的源字符串。
fromEncoding:转换前的字符编码。
toEncoding:要转换成为的字符编码。
paramName:转换后的目标字符串。
把字符编码转换为UTF-8格式,用法如下:
lr_convert_string_encoding("汽车",LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str");