1. 程式人生 > 實用技巧 >LoadRunner(八)、常用的介面壓測格式

LoadRunner(八)、常用的介面壓測格式

一、html請求

Action()
{
    web_reg_save_param("return",
        "LB=",
        "RB=",
        "Search=All",
        LAST);
    web_custom_request("web_custom_request",
              "URL=http://172.20.100.63:31085/ups/services/receiveMsg",
                "Method=POST",
                "Resource=0",
                
"Referer=", "Mode=HTTP", "EncType=text/html;charset=UTF-8", "Body=<?xml version='1.0' encoding='UTF-8'?>" "<message>" "<header>" "<TransactionID>135</TransactionID>" "
<Timestamp>2017-06-14 17:05:13</Timestamp>" "<OpCode>PORTAL_QUERY_UNIFIED_PAY_STATUS</OpCode>" "<MsgType>REQ</MsgType>" "<Version>1.0</Version>" "</header>" "<body>" "
<UnifiedPayStatus>" "<OrderId>BOSS201708171843500684811</OrderId>" "</UnifiedPayStatus>" "</body>" "</message>", LAST); lr_convert_string_encoding(lr_eval_string("{return}"),"utf-8",NULL,"msg"); //返回訊息亂碼,此處把返回訊息轉化成utf-8,儲存到msg中 lr_output_message(lr_eval_string("{msg}")); return 0; }

二、JSON請求

Action()

{
   web_reg_save_param("Return", 
        "LB=", 
        "RB=", 
        LAST ); 


     web_custom_request("web_custom_request",

        "URL=http://172.20.100.63:31085/SyncUnifiedPayStatus",
        "Method=POST",
              "Resource=1",
        "RecContentType=application/json",
              "EncType=application/json",
              "Body={
                  \"orderId\":\"BOSS201708311002021249643\",
                \"state\":\"00\",
                  \"purchaseTime\":\"2017-06-15 10:05:05\",
                  \"enableTime\":\"2017-06-15 10:05:05\",
            \"disableTime\":\"2018-07-25 12:05:05\",
            \"payType\":\"02\"
            }",
                 LAST);
   lr_output_message(lr_eval_string("<Return>"));
   return 0;
}

指令碼說明:
1、雙引號前要加\進行轉義,避免和lr裡面的雙引號衝突;
2、修改Tools》General Options 下面引數大括號{}修改為<>,避免lr把JSON串中的{}誤認為引數化的{};