TA的每日心情 | 开心 2017-4-17 09:07 |
---|
签到天数: 3 天 连续签到: 1 天 [LV.2]测试排长
|
代码如下:
Action()
{
//char msg1[] ="Body=TEST" ;
char *body=NULL;
char line[1024*8];
char *cookiebuff=NULL;
int fpcookie;
int filesize=0;
int fp;
fp=fopen("D:\\test\\test.txt","r");
if(fp <=0)
{
lr_output_message("open file fail!!");
}
fseek(fp,0,0);
fseek(fp,0,2);
filesize=ftell(fp);// filesize就是文件的长度
fseek(fp,0,0);
if(filesize <=0)
{
body=(char*)malloc(sizeof(char)*1024);
if(body == NULL) return;
memset(line,0,sizeof(line));
//strcat(body,msg1);
}
else
{
int bodysize = 1024*1024*2;// body大小
char *tempbuffer; //缓存样本数据
int sizecount = 0;
int readsize = 1024*1024; //样本数据大小,不大于样本文件大小
body=(char*)malloc(bodysize);
if(body == NULL) return;
memset(body,0,bodysize);
//memcpy(body,msg1,sizeof(msg1));
tempbuffer = (char*)malloc(filesize);
memset(tempbuffer, 0, filesize);
while(1){
fread(tempbuffer, readsize, 1, fp);
if(sizecount*readsize> bodysize - readsize) break;
memcpy(body + sizecount * readsize, tempbuffer, readsize);
sizecount++;
}
free(tempbuffer);
}
fclose(fp);
filesize=0;
fpcookie=fopen("D://test//cookie.txt","rb");
if(fpcookie <= 0)
{
lr_output_message("open cookie file fail!!");
}
fseek(fpcookie,0,0);
fseek(fpcookie,0,2);
filesize=ftell(fpcookie);// filesize就是文件的长度
fseek(fpcookie,0,0);
if(filesize <=0)
{
lr_output_message("open cookie file fail,the length is 0!!");
cookiebuff=(char*)malloc(sizeof(char)*5);
if(cookiebuff == NULL) return;
memset(cookiebuff,0,5);
strcat(cookiebuff,"MULL");
}
else
{
int cookiesize = 1024*10;// cookie大小
char *tempbuffer;
int sizecount = 0;
int readsize = 7*1024;//样本数据大小,不大于样本文件的大小
cookiebuff=(char*)malloc(cookiesize);
if(cookiebuff == NULL) return;
memset(cookiebuff,0,cookiesize);
tempbuffer = (char*)malloc(filesize);
memset(tempbuffer, 0, filesize);
fread(tempbuffer, readsize, 1, fpcookie);
while(1){
if(sizecount*readsize > cookiesize - readsize) break;
memcpy(cookiebuff + sizecount * readsize, tempbuffer, readsize);
sizecount++;
}
free(tempbuffer);
}
fclose(fpcookie);
filesize=0;
web_add_auto_header("User-Agent","K-Touch_T566_CMCC_TD/TBT910514_7470_V0801/10.25.2009 Browser/NF3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1");
web_add_auto_header("ACCEP", "text/html,image/gif, application/xml;q=0.9, text/vnd.wap.wml, application/vnd.wap.xhtml+xml");
web_add_auto_header("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
web_add_auto_header("Accept-Charset","UTF-8,gb2312,gbk,ISO-8859-1,US-ASCII,Big5,ISO-10646-UCS-2;q=0.600");
web_add_auto_header("Accept-Encoding","deflate, gzip");
web_add_header("Cookie",cookiebuff);
web_custom_request("test",
"Method=GET",
"URL=http://10.47.160.11:8080/test.gif",
body,
"TargetFrame=",
LAST);
free(cookiebuff);
free(body);
return 0;
} |
|