首页 技术 正文
技术 2022年11月15日
0 收藏 552 点赞 5,007 浏览 2509 个字

上传文件的本质是浏览器读取本地文件的内容,以二进制数据方式传输到服务端,服务端新建一个文件,将获取到的数据复制到文件中

LR中上传操作可以通过web_submit_data函数实现,支持录制
要点:
web_add_header(“Content-type”,”multipart/form-data”)或者Enctype=“multipart/form-data”

一般情况需要加 web_add_header(“Content-Type”,”multipart/form-data”);

 Action()
{
web_reg_save_param("fin_msg",
"LB=",
"RB=",
"Ord=1",
"Search=Body",
LAST); web_add_header("Content-Type","multipart/form-data"); lr_start_transaction("form-data"); //上传文件---函数 web_submit_data
web_submit_data("Attachments", "Action=http://localhost:8080/pinter/file/api/upload", "Method=POST", "EncType=multipart/form-data", "TargetFrame=", "RecContentType=text/html", "Snapshot=t5.inf", "Mode=HTML", ITEMDATA, "Name=file", "Value=C:\\a.txt", "File=yes",
ENDITEM, LAST ); lr_convert_string_encoding(lr_eval_string("{fin_msg}"), LR_ENC_UTF8, LR_ENC_SYSTEM_LOCALE, "Account"); if(strcmp(lr_eval_string("{Account}"), "上传成功") == ){
lr_end_transaction("form-data", LR_PASS); }else{
lr_end_transaction("form-data", LR_FAIL); } return ;
}

运行后日志如下:

 Virtual User Script started at : -- ::
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0. for WINXP; build (Aug ::) [MsgId: MMSG-]
Run Mode: HTML [MsgId: MMSG-]
Run-Time Settings file: "C:\test_huzhenyu\Script\biao_dan_upload\\default.cfg" [MsgId: MMSG-]
Ending action vuser_init.
Running Vuser...
Starting iteration .
Starting action Action.
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): Warning -: The header being added may cause unpredictable results when applied to all ensuing URLs. It is added anyway [MsgId: MWAR-]
Action.c(): web_add_header("Content-Type") highest severity level was "warning" [MsgId: MMSG-]
Action.c(): Notify: Transaction "form-data" started.
Action.c(): t=618ms: -byte response headers for "http://localhost:8080/pinter/file/api/upload" (RelFrameId=, Internal ID=)
Action.c(): HTTP/1.1 \r\n
Action.c(): Content-Type: text/plain;charset=UTF-\r\n
Action.c(): Content-Length: \r\n
Action.c(): Date: Sat, Mar :: GMT\r\n
Action.c(): \r\n
Action.c(): t=643ms: -byte response body for "http://localhost:8080/pinter/file/api/upload" (RelFrameId=, Internal ID=)
Action.c(): 涓婁紶鎴愬姛
Action.c(): Notify: Saving Parameter "fin_msg = 涓婁紶鎴愬姛".
Action.c(): web_submit_data("Attachments") was successful, body bytes, header bytes [MsgId: MMSG-]
Action.c(): Notify: Parameter Substitution: parameter "fin_msg" = "涓婁紶鎴愬姛"
Action.c(): Notify: Saving Parameter "Account = 上传成功\x00".
Action.c(): Notify: Parameter Substitution: parameter "Account" = "上传成功\x00"
Action.c(): Notify: Transaction "form-data" ended with "Pass" status (Duration: 0.6063 Wasted Time: 0.3921).
Ending action Action.
Ending iteration .
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.

log

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,738
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,129
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292