Loadrunner上傳檔案與下載檔案指令碼

來源:互聯網
上載者:User

標籤:set   nload   檔案大小   erer   string   turn   blog   erro   item   

Loadrunner上傳與下載檔案指令碼

一、 上傳指令碼

 

Action(){int uploadImgStatus = 0;  //擷取上傳產品圖IDweb_reg_save_param_ex("ParamName=imgRandName","LB=\"sourceImgPath\":\"upload\\/cropzoomimg\\/","RB=\"}",LAST);uploadImgStatus = web_submit_data("CropZoomImgController.do","Action=http://192.168.2.67:7001/CropZoomImgController.do?method=uploadSourceImg","Method=POST","EncType=multipart/form-data","Referer=http://192.168.2.67:7001/GoodsController.do?method=toCreateGoods","Snapshot=t377.inf","Mode=HTTP",ITEMDATA,"Name=attachFile", "Value=G:\\123.txt", "File=Yes", ENDITEM,LAST);if (uploadImgStatus == 1) {  //如果上傳失敗則終止指令碼lr_abort();lr_error_message("上傳失敗!");} else {   //輸出上傳圖片ID(調試使用)lr_output_message("%s", lr_eval_string("{imgRandName}"));}return 0;}

二、下載指令碼

Action(){//定義一個整型變數儲存獲得檔案的大小int flen; //儲存檔案控制代碼long filedes; //儲存檔案路徑及檔案名稱char file[256]="\0"; char * chNumber ;int time;//設定頁面接收最大的位元組數,該設定應大於下載檔案的大小web_set_max_html_param_len("1024000"); //並發開始web_concurrent_start(NULL);//使用關聯函數擷取下載檔案的內容web_reg_save_param("filecontent","LB=","RB=","Search=BODY",LAST); web_url("android.apk",//下載連結"URL=http://res.t.ifeng.com/download/android/ifeng_weibo_android_v1.01beta.apk","Resource=1","RecContentType=application/force-download","Referer=",LAST);//並髮結束web_concurrent_end(NULL); //獲得下載檔案大小flen =web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); time=web_get_int_property (HTTP_INFO_DOWNLOAD_TIME);lr_output_message("下載時間是%d",time);//產生隨機數chNumber=lr_eval_string("{NewParam}"); //將下載檔案要儲存的路徑存到file裡strcat(file,"F:\\file");//在檔案名稱後自動產生隨機數strcat(file,chNumber);//下載的檔案尾碼名稱strcat(file,".apk");if(flen > 0){if((filedes = fopen(file,"wb")) == NULL){lr_output_message("Open FileFailed!", lr_eval_string("{filecontent}"));return -1;}fwrite(lr_eval_string("{filecontent}"),flen,1,filedes );fclose( filedes );}return 0;}

 

Loadrunner上傳檔案與下載檔案指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.