- <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");