📄 http.c
字号:
};//if(0==strcmp("200",r_Respone_Code))
break;
case 14://POST /term/savetodb.asp
i=4380;
if(send(sock,s_HTMLStr,i,0)<0)//发送准备好的内容buf,长度是s
{
closesocket(sock);
printf_view("NT_Send_Server send error ");
return FAIL;
}
//i_HTMLLen=i_HTMLLen-i;
//i=2670;
//if(send(sock,(char*)(s_HTMLStr+1470),i,0)<0)//发送准备好的内容buf,长度是s
//{
// closesocket(sock);
// printf_view("NT_Send_Server send error ");
// return FAIL;
//}
i_HTMLLen=i_HTMLLen-i;
if(send(sock,(char*)(s_HTMLStr+4380),i_HTMLLen,0)<0)//发送准备好的内容buf,长度是s
{
closesocket(sock);
printf_view("NT_Send_Server send error ");
return FAIL;
}
sendflag=0;//已发送
recvflag=1;//要接收
sent=0;
recved=0;
iState=18;
break;
case 18://GET /term/logout.asp
//分析回复消息
if(1==recved)//已经收到数据
{
i=Get_HTTPRespone(rec,
r_Respone_Version,
r_Respone_Code,
r_Respone_Mark,
r_Server,
r_Date,
r_Content_Length,
r_Content_Type,
r_Cache_control,
r_Accept_Ranges,
r_Last_Modified,
r_ETag,
r_Expires,
r_Set_Cookie,
&i_HeadLen);
s_iLen=recvlen-i_HeadLen;//HTML长度为接收长度减去头长度
iALen=Get_HTMLData((rec+i_HeadLen),
s_iLen,
s_href,
s_src,
s_action,
s_inputname,
s_inputtype,
s_inputvalue,
s_inputid,
s_inputsize);
}
if(0==strcmp("200",r_Respone_Code))
{//回复成功,继续处理//HTML中出现“GotData OK!”就算收到,否则可能是密码不对等其它原因
sprintf(s_Method,"GET");//
sprintf(s_URI,"/term/logout.asp");
sprintf(s_Version,"HTTP/1.1");
sprintf(s_Accept,"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*");//
sprintf(s_Referer,"http://192.168.6.33/term/myterm.asp?action=myterm");
sprintf(s_Accept_Language,"zh-cn");
sprintf(s_Content_Type,"");//
sprintf(s_Accept_Encoding,"gzip, deflate");
sprintf(s_User_Agent,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; WPS; TencentTraveler )");
sprintf(s_Host,server_addr);
sprintf(s_Connection,"Keep-Alive");
sprintf(s_Cache_Control,"");
//如果回复中要求,重设Cookie
if(0<strlen(r_Set_Cookie))
{
bufBegin=r_Set_Cookie;
bufEnd=strstr(r_Set_Cookie,";");
strncpy(s_Cookie,bufBegin,(bufEnd-bufBegin));
s_Cookie[bufEnd-bufBegin]=0;
}
//sprintf(s_Cookie,r_Set_Cookie);
//sprintf(s_Cookie,"ASPSESSIONIDQSCDCCSS=INKLMCPCAHBICOIFENPMBLJO");
//strcpy(s_HTMLStr,"termsn=13907810781&comeurl=http%3A%2F%2F192.168.6.33%2Fterm%2Findex.asp&snpassword=b1e3445679573fe6&Submit=%E7%BB%88%E7%AB%AF%E7%99%BB%E5%BD%95");//
//sprintf(s_HTMLStr,"termsn=13907810781&comeurl=http://192.168.6.33/term/index.asp&snpassword=b1e3445679573fe6&Submit=终端登陆");//
sprintf(s_HTMLStr,"");//
i_HTMLLen=strlen(s_HTMLStr);
sprintf(s_Content_Length,"");
//组装GET消息
s=Make_HTTPRequest(buf,
s_Method,
s_URI,
s_Version,
s_Referer,
s_Accept,
s_Accept_Language,
s_Content_Type,
s_Accept_Encoding,
s_User_Agent,
s_Host,
s_Content_Length,
s_Connection,
s_Cache_Control,
s_Cookie,
s_HTMLStr,
i_HTMLLen);
}
sendflag=1;//要发送
recvflag=1;//要接收
sent=0;
recved=0;
iState=20;
break;
case 19://直接POST /term/savetodb.asp
{//内容中包括密码
sprintf(s_Method,"POST");//
sprintf(s_URI,"/term/savetodb.asp");
sprintf(s_Version,"HTTP/1.1");
sprintf(s_Accept,"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*");//
sprintf(s_Referer,"http://192.168.6.33/term/myterm.asp?action=upload");
sprintf(s_Accept_Language,"zh-cn");
sprintf(s_Content_Type,"multipart/form-data; boundary=---------------------------7d838432100202");//
sprintf(s_Accept_Encoding,"gzip, deflate");
sprintf(s_User_Agent,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; WPS; TencentTraveler )");
sprintf(s_Host,server_addr);
sprintf(s_Connection,"Keep-Alive");
sprintf(s_Cache_Control,"no-cache");
sprintf(s_Cookie,"");//没有s_Cookie
//如果回复中要求,重设Cookie
//if(0<strlen(r_Set_Cookie))
//{
// bufBegin=r_Set_Cookie;
// bufEnd=strstr(r_Set_Cookie,";");
// strncpy(s_Cookie,bufBegin,(bufEnd-bufBegin));
// s_Cookie[bufEnd-bufBegin]=0;
//}
//sprintf(s_Cookie,"ASPSESSIONIDQSSRRBCA=MKNFDBKBLKPCBMOLDPDBECLM; mobileye=name=13907810781");
sprintf(s_HTMLStr,"");//数据在下一状态发送。但要先组装以便记录长度
i_HTMLLen=0;
//用buf作临时空间
//for(i=0;i<8;i++)//组装各个INPUT参数
{
//if(0<strlen(s_inputname[i]))//参数存在
{
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","title");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","test1");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"; filename=\"%s\"\r\n","picture","D:\\comgate\\comgate\\dog.jpg");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n\r\n","Content-Type: image/pjpeg");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
//图象数据
//FILE *hd;
hd=fopen("D:\\comgate\\comgate\\dog.jpg","rb");//取文件名
recvlen=LongStrLen;
s_iLen=fread(&buf,1,recvlen,hd);//先写一部分
if(0<s_iLen)
{
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,s_iLen);
i_HTMLLen=i_HTMLLen+s_iLen;
};
fclose(hd);
sprintf(buf,"\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
//
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"; filename=\"%s\"\r\n","sound","");//没有sound文件
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n\r\n","Content-Type: application/octet-stream");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"\r\n");//空数据,但要有这项
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","text");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","test2");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","gottime");//标题
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","2008-3-4 10:17:28");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","shottime");//标题
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","2008-3-4 10:17:28");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","senttime");//标题
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","2008-3-4 10:17:28");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","termsn");//标题
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","13907810781");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","termport");//标题
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","1");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","termpassword");//标题
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","12345");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","mtnumber");//标题
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","1");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"-----------------------------7d838432100202\r\n");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"Content-Disposition: form-data; name=\"");
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\"\r\n\r\n","Enter");//标题
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
sprintf(buf,"%s\r\n","Upload");//内容
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
//
sprintf(buf,"-----------------------------7d838432100202--\r\n");//数据结束
memcpy((char*)(s_HTMLStr+i_HTMLLen),buf,strlen(buf));
i_HTMLLen=i_HTMLLen+strlen(buf);
};//if(0<strlen(s_inputname[i]))
};//for(i-0;i<8;i++)
//
sprintf(s_Content_Length,"%i",i_HTMLLen);//数据长度
//组装GET消息
s=Make_HTTPRequest(buf,
s_Method,
s_URI,
s_Version,
s_Referer,
s_Accept,
s_Accept_Language,
s_Content_Type,
s_Accept_Encoding,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -