1. GET方式的HTTP请求性能测试脚本
Action() { web_set_max_html_param_len("10000"); web_reg_save_param("retCode", "LB=retCode\":\"", "RB=\"", "NotFound=WARNING", LAST); lr_start_transaction("test"); web_custom_request("test ", "URL=http://127.0.0.1/test?channelno=1&phoneno=12345678912", "Method=GET", "Resource=0", "Referer=", "Mode=HTTP", "EncType=txt/html; charset=UTF-8", "Body=", LAST); if (!strcmp(lr_eval_string("{retCode}"),"000000")) { lr_output_message("Successfull, retcode is:%s", lr_eval_string("{retCode}")); lr_end_transaction("test", LR_PASS); } else{ lr_error_message("Failed, retcode is:%s", lr_eval_string("{retCode}")); lr_end_transaction("test", LR_FAIL); } return 0; } |
2. POST格式的json串请求
Action() { web_reg_save_param("retCode", "LB=retCode\":\"", "RB=\"", "NotFound=WARNING", LAST); lr_start_transaction("test"); web_add_header("Content-Type" ,"application/json"); web_custom_request("test", "URL=http://127.0.0.1/test ", "Method=POST", "Resource=0", "Referer=", "Mode=HTTP", "EncType=application/json; charset=UTF-8", "RecContentType=application/json", "Body={\"channelNo\":\"{channelNo}\",\" phoneno \":12345678900,\"createdTime\":\"{createdTime}\"}", LAST); if (!strcmp(lr_eval_string("{retCode}"),"000000")) { lr_output_message("Successfull, retcode is:%s", lr_eval_string("{retCode}")); lr_end_transaction("test ", LR_PASS); } else{ lr_error_message("Failed, retcode is:%s", lr_eval_string("{retCode}")); lr_end_transaction("test ", LR_FAIL); } return 0; } |
说明:在编写json串时,注意保证body内容的正确性,字符串必须在\" \"之间,参数名称与参数值之间是:,参数与参数之间用逗号分隔