vuser_init()
{
char fileName[] = "D:/Script/CreateObj_10M/tools.zip";
int len = 0;
int readLen=0;
int tmpLen=1;
int runLen =104857;
int cLen = 0;
if ( (file_stream = fopen(fileName, "rb")) == NULL)
{
lr_message("open file failed!\n");
return -1;
}
fseek(file_stream, 0, 2);
len = ftell(file_stream);
lr_message("file length is: %d bytes", len);
readbuf = (char *) malloc(len+1);
memset(readbuf, 0, len+1);
if ( runLen > len) {
runLen = len;
}
fseek(file_stream, 0, 0);
while(feof(file_stream)== 0){
tmpLen = fread(readbuf + readLen, 1,runLen , file_stream);
readLen += tmpLen;
cLen = readLen + runLen;
if (cLen > len) {
runLen = cLen - len;
}
if (tmpLen==0) {
break;
}
}
//关闭文件句柄
fclose(file_stream);
//保存参数
lr_save_string(readbuf,"bodys");
}
Action()
{
lr_start_transaction("CreateObj_1M");
web_add_header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8..");
web_add_header("Content-Type", "text/plain; charset=UTF-8");
web_add_header("Authorization", "YWS {userkey}:XXXXXXX");
web_custom_request("CreateObj",
"Method=PUT",
"TargetFrame=",
"Resource=0",
"RecContentType=application/xml",
"Referer=",
"Mode=HTML",
"Body={bodys}", //如果是二进制文件,可以改成BodyBinary
LAST );
returnCode = web_get_int_property(HTTP_INFO_RETURN_CODE);
if ( returnCode!=201 ) {
lr_end_transaction("CreateObj_1M",LR_FAIL);
}else{
lr_end_transaction("CreateObj_1M",LR_PASS);
}
return 0;
}
|