1. 程式人生 > >post接口_form表單上傳

post接口_form表單上傳

Enctype ide show cal 瀏覽器 esp register bsp 進制

上傳文件的本質是瀏覽器讀取本地文件的內容,以二進制數據方式傳輸到服務端,服務端新建一個文件,將獲取到的數據復制到文件中

LR中上傳操作可以通過web_submit_data函數實現,支持錄制
要點:
web_add_header(“Content-type”,”multipart/form-data”)或者Enctype=“multipart/form-data”

一般情況需要加 web_add_header("Content-Type","multipart/form-data");

 1 Action()
 2
{ 3 web_reg_save_param("fin_msg", 4 "LB=", 5 "RB=", 6 "Ord=1", 7 "Search=Body", 8 LAST); 9 10 web_add_header("Content-Type","multipart/form-data"); 11 12 lr_start_transaction("form-data"); 13 14 //上傳文件---函數 web_submit_data 15
web_submit_data("Attachments", 16 17 "Action=http://localhost:8080/pinter/file/api/upload", 18 19 "Method=POST", 20 21 "EncType=multipart/form-data", 22 23 "TargetFrame=", 24 25 "RecContentType=text/html", 26 27 "Snapshot=t5.inf", 28 29 "Mode=HTML",
30 31 ITEMDATA, 32 33 "Name=file", 34 35 "Value=C:\\a.txt", 36 37 "File=yes", 38 ENDITEM, 39 40 LAST ); 41 42 lr_convert_string_encoding(lr_eval_string("{fin_msg}"), LR_ENC_UTF8, LR_ENC_SYSTEM_LOCALE, "Account"); 43 44 45 if(strcmp(lr_eval_string("{Account}"), "上傳成功") == 0){ 46 lr_end_transaction("form-data", LR_PASS); 47 48 49 }else{ 50 lr_end_transaction("form-data", LR_FAIL); 51 52 53 } 54 55 56 return 0; 57 }

運行後日誌如下:

技術分享圖片
 1 Virtual User Script started at : 2019-03-16 17:24:13
 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\biao_dan_upload\\default.cfg"      [MsgId: MMSG-27141]
 6 Ending action vuser_init.
 7 Running Vuser...
 8 Starting iteration 1.
 9 Starting action Action.
10 Action.c(3): Registering web_reg_save_param was successful      [MsgId: MMSG-26390]
11 Action.c(10): 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(10): web_add_header("Content-Type") highest severity level was "warning"      [MsgId: MMSG-26391]
13 Action.c(12): Notify: Transaction "form-data" started.
14 Action.c(15): t=618ms: 114-byte response headers for "http://localhost:8080/pinter/file/api/upload" (RelFrameId=1, Internal ID=1)
15 Action.c(15):     HTTP/1.1 200 \r\n
16 Action.c(15):     Content-Type: text/plain;charset=UTF-8\r\n
17 Action.c(15):     Content-Length: 12\r\n
18 Action.c(15):     Date: Sat, 16 Mar 2019 09:24:14 GMT\r\n
19 Action.c(15):     \r\n
20 Action.c(15): t=643ms: 12-byte response body for "http://localhost:8080/pinter/file/api/upload" (RelFrameId=1, Internal ID=1)
21 Action.c(15):     涓婁紶鎴愬姛
22 Action.c(15): Notify: Saving Parameter "fin_msg = 涓婁紶鎴愬姛".
23 Action.c(15): web_submit_data("Attachments") was successful, 12 body bytes, 114 header bytes      [MsgId: MMSG-26386]
24 Action.c(42): Notify: Parameter Substitution: parameter "fin_msg" =  "涓婁紶鎴愬姛"
25 Action.c(42): Notify: Saving Parameter "Account = 上傳成功\x00".
26 Action.c(45): Notify: Parameter Substitution: parameter "Account" =  "上傳成功\x00"
27 Action.c(46): Notify: Transaction "form-data" ended with "Pass" status (Duration: 0.6063 Wasted Time: 0.3921).
28 Ending action Action.
29 Ending iteration 1.
30 Ending Vuser...
31 Starting action vuser_end.
32 Ending action vuser_end.
33 Vuser Terminated.
log

post接口_form表單上傳