LR三:post接口_ajax上传
1 Action() 2 { 3 4 5 6 web_reg_save_param("find_msg", 7 "LB=message\":\"", 8 "RB=\"", 9 "Ord=1", 10 LAST); 11 12 13 14 //特殊情况需要加 15 web_add_header("Content-Type","multipart/form-data"); 16 17 18 lr_start_transaction("ajax_upload"); 19 20 21 web_submit_data("Attachments", 22 23 "Action=http://localhost:8080/pinter/file/api/upload2", 24 25 "Method=POST", 26 27 "EncType=multipart/form-data", 28 29 "TargetFrame=", 30 31 "RecContentType=text/html", 32 33 "Snapshot=t5.inf", 34 35 "Mode=HTML", 36 37 ITEMDATA, 38 39 "Name=file", 40 41 "Value=C:\\a.txt", 42 43 "File=yes", 44 ENDITEM, 45 46 LAST ); 47 48 //utf8->转化为本地解码 49 lr_convert_string_encoding(lr_eval_string("{find_msg}"), LR_ENC_UTF8, LR_ENC_SYSTEM_LOCALE, "msg"); 50 51 52 if(strcmp(lr_eval_string("{msg}"),"上传成功") == 0){ 53 lr_end_transaction("ajax_upload", LR_PASS); 54 55 }else{ 56 lr_end_transaction("ajax_upload", LR_FAIL); 57 58 } 59 60 61 62 return 0; 63 }
运行日志如下:
1 Virtual User Script started at : 2019-03-15 15:12:11 2 Starting action vuser_init. 3 Web Turbo Replay of LoadRunner 11.0.0 for WINXP; build 8859 (Aug 18 2010 20:14:31) [MsgId: MMSG-27143] 4 Run Mode: HTML [MsgId: MMSG-26000] 5 Run-Time Settings file: "C:\test_huzhenyu\Script\upload_ajax\\default.cfg" [MsgId: MMSG-27141] 6 Ending action vuser_init. 7 Running Vuser... 8 Starting iteration 1. 9 Starting action Action. 10 Action.c(6): Registering web_reg_save_param was successful [MsgId: MMSG-26390] 11 Action.c(15): Warning -26593: The header being added may cause unpredictable results when applied to all ensuing URLs. It is added anyway [MsgId: MWAR-26593] 12 Action.c(15): web_add_header("Content-Type") highest severity level was "warning" [MsgId: MMSG-26391] 13 Action.c(18): Notify: Transaction "ajax_upload" started. 14 Action.c(21): t=553ms: 128-byte response headers for "http://localhost:8080/pinter/file/api/upload2" (RelFrameId=1, Internal ID=1) 15 Action.c(21): HTTP/1.1 200 \r\n 16 Action.c(21): Content-Type: application/json;charset=UTF-8\r\n 17 Action.c(21): Transfer-Encoding: chunked\r\n 18 Action.c(21): Date: Fri, 15 Mar 2019 07:12:12 GMT\r\n 19 Action.c(21): \r\n 20 Action.c(21): t=581ms: 4-byte chunked response overhead for "http://localhost:8080/pinter/file/api/upload2" (RelFrameId=1, Internal ID=1) 21 Action.c(21): 31\r\n 22 Action.c(21): t=590ms: 7-byte chunked response overhead for "http://localhost:8080/pinter/file/api/upload2" (RelFrameId=1, Internal ID=1) 23 Action.c(21): \r\n 24 Action.c(21): 0\r\n 25 Action.c(21): \r\n 26 Action.c(21): t=621ms: 49-byte chunked response body for "http://localhost:8080/pinter/file/api/upload2" (RelFrameId=1, Internal ID=1) 27 Action.c(21): {"code":"0","message":"涓婁紶鎴愬姛","data":null} 28 Action.c(21): Notify: Saving Parameter "find_msg = 涓婁紶鎴愬姛". 29 Action.c(21): HTML parsing not performed for Content-Type "application/json" ("ParseHtmlContentType" Run-Time Setting is "TEXT"). URL="http://localhost:8080/pinter/file/api/upload2" [MsgId: MMSG-26548] 30 Action.c(21): web_submit_data("Attachments") was successful, 49 body bytes, 128 header bytes, 11 chunking overhead bytes [MsgId: MMSG-26385] 31 Action.c(49): Notify: Parameter Substitution: parameter "find_msg" = "涓婁紶鎴愬姛" 32 Action.c(49): Notify: Saving Parameter "msg = 上传成功\x00". 33 Action.c(52): Notify: Parameter Substitution: parameter "msg" = "上传成功\x00" 34 Action.c(53): Notify: Transaction "ajax_upload" ended with "Pass" status (Duration: 0.5931 Wasted Time: 0.4267). 35 Ending action Action. 36 Ending iteration 1. 37 Ending Vuser... 38 Starting action vuser_end. 39 Ending action vuser_end. 40 Vuser Terminated.