VC++ 模拟表单提交
来源:互联网 发布:炫踪网络上市消息 编辑:程序博客网 时间:2024/05/21 12:40
http://blog.csdn.net/wangningyu/article/details/4526357
http://www.33vc.com/index.php/archives/3687
首先用Httplook 来查看表单提交的内容。
以下函数能够模拟表单提交
bool CCHttpSockDlg::PostContent(CString strUrl, const CString &strPara, CString &strContent, CString &strDescript)
{
try{
strDescript = "提交成功完成!";
bool bRet = false;
CString strServer, strObject, strHeader, strRet;
unsigned short nPort;
DWORD dwServiceType;
if(!AfxParseURL(strUrl, dwServiceType, strServer, strObject, nPort))
{
strDescript = strUrl + "不是有效有网络地址!";
return false;
}
CInternetSession sess;//Create session
CHttpFile* pFile;
//////////////////////////////////////////////
CHttpConnection *pServer = sess.GetHttpConnection(strServer, nPort);
if(pServer == NULL)
{
strDescript = "对不起,连接服务器失败!";
return false;
}
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strObject,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
if(pFile == NULL)
{
strDescript = "找不到网络地址" + strUrl;
return false;
}
// pFile -> AddRequestHeaders("Content-Type: text/xml; charset=utf-8");
pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
pFile -> AddRequestHeaders("Accept: */*");
pFile -> SendRequest(NULL, 0, (LPTSTR)(LPCTSTR)strPara, strPara.GetLength());
CString strSentence;
DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus);
BOOL bSuccess = pFile->QueryInfo(
HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
&dwStatus, &dwBuffLen);
if( bSuccess && dwStatus>= 200 && dwStatus<300)
{
char buffer[2049];
memset(buffer, 0, 2049);
int nReadCount = 0;
while((nReadCount = pFile->Read(buffer, 2048)) > 0)
{
strContent += buffer;
memset(buffer, 0, 2049);
}
bRet = true;
}
else
{
strDescript = "网站服务器错误" + strUrl;
bRet = false;
}
////////////////////////////////////////
pFile->Close();
sess.Close();
return bRet;
}
catch(...)
{
int nCode = GetLastError();
strDescript.Format("向服务器post失败!错误号:%d", nCode);
return false;
}
}
调用方法(这是自动在www.whctwl.com提交留言的方法)
CString strContent,strDescrip;
PostContent(_T("http://www.whctwl.com/message.asp"),_T("Title=asdfasd&OwnerName=werwer&Phone=232323&Email=232@qq.com&Homepage=&Content=asdfasdf&Version=cn&IsChecked=False&acction=add&sub=%B7%A2%B1%ED"),strContent,strDescrip);
- VC++ 模拟表单提交
- PHP模拟表单提交
- HttpClient4模拟表单提交
- httpClient 模拟表单提交
- 模拟post表单提交
- 模拟表单提交
- nodejs模拟表单提交
- VC提交表单
- VC Http提交表单
- VC模拟POST提交
- VC模拟POST提交
- 模拟表单提交的例子
- winform模拟post提交表单
- java代码 模拟表单提交
- 用python模拟提交表单
- delphi webbrowser 模拟表单提交
- JS 模拟动态表单提交
- Java 模拟form表单提交
- Android SDK更新以及ADT更新出现问题的解决办法(附google服务器地址)
- DM6446 uboot分析
- dex2jar 使用方法
- socket编程 与c通信
- SQL语句集锦——数据库表查询、更新、删除等SQL语法
- VC++ 模拟表单提交
- ns-3实验环境搭建(上)
- C语言:五大基本排序算法
- 八大排序
- 代理键的理解
- ORACLE索引
- 非静态的字段、方法或属性……要求对象引用【學習】要求對象引用?
- LeetCode: Spiral Matrix II
- Java中的Enum的使用与分析