wininet 提交表单content_lenght始终为0

jobsccnu 2009-10-31 12:21:38
下面是我的一个完整的登录,发帖的过程,
现在登录已经成功了,但是发帖失败,
我抓取数据包发现,我每次发出去的数据的Content-Length: 0
但是直接再网页上执行,这个是:Content-Length: 123
不知道哪位高人可以指点一下,谢谢。

CInternetSession session(_T("My Browser2"));
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
CString strAddress = "http://bbs.zynews.com/login.aspx?loginsubmit=true";

try
{
CString strServer;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;

if(!AfxParseURL(strAddress,dwServiceType,strServer,strObject,nPort)||
dwServiceType != INTERNET_SERVICE_HTTP)
{
MessageBox(_T("不是HTTP站点"),_T("错误"));
}
pServer = session.GetHttpConnection(strServer,nPort);

//===================================登录(打开登陆页面)===============================================
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strObject,NULL,1,NULL,NULL, INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT );
pFile->AddRequestHeaders(_T("My Browser2"));
pFile->SendRequest();

DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);

//===================================登录(进行登陆操作)===============================================
CString strFormatData = "username=joyswgood&password=ghygood1&question=0&answer=&expires=43200&templateid=0&login=%E7%99%BB%E5%BD%95";//for 中原网
pFile->AddRequestHeaders("Accept-Language: zh-cn\r\n");
pFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded\r\n");
pFile->AddRequestHeaders("Accept-Encoding: gzip, deflate\r\n");
BOOL ret = pFile->SendRequest(0,0,(LPVOID)strFormatData.GetBuffer(),strFormatData.GetLength());
if(ret)
{
ret = pFile->QueryInfoStatusCode(dwRet);
TRACE("login dwRet = %d\n",dwRet);

CString a;
FILE *fp = fopen("c:\\login.html","w+");
while(pFile->ReadString(a))
{
fprintf(fp,"%s",a);
}
fclose(fp);
}
pFile->Close();

//===================================发帖(打开发帖页面)===============================================

strAddress = "http://bbs.zynews.com/postreply.aspx?topicid=8717";
if(!AfxParseURL(strAddress,dwServiceType,strServer,strObject,nPort)|| dwServiceType != INTERNET_SERVICE_HTTP)
{
MessageBox(_T("不是HTTP站点"),_T("错误"));
}

pFile = pServer->OpenRequest(0,strObject,NULL,1,NULL,NULL, INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT );
pFile->AddRequestHeaders(_T("My Browser"));
pFile->SendRequest();

pFile->QueryInfoStatusCode(dwRet);
TRACE("open[%s] = %d\n",strObject,dwRet);

//===================================发帖(进行发帖操作)===============================================
CString key = _T("7d91f3931e8c");
CString strHeadData;

strHeadData.Format(_T("Content-Type: multipart/form-data; boundary=---------------------------%s\r\n"),key);
strFormatData.Format(_T("-----------------------------%s\r\n"
"Content-Disposition: form-data; name=\"usesig\"\r\n\r\n"
"1\r\n"
"-----------------------------%s\r\n"
"Content-Disposition: form-data; name=\"postreplynotice\"\r\n\r\n"
"on\r\n"
"-----------------------------%s\r\n"
"Content-Disposition: form-data; name=\"title\"\r\n\r\n"
"da jia hao\r\n"
"-----------------------------%s\r\n"
"Content-Disposition: form-data; name=\"postid\"\r\n\r\n"
"-1\r\n"
"-----------------------------%s\r\n"
"Content-Disposition: form-data; name=\"message\"\r\n\r\n"
"sshang hai huanying nin\r\n"
"-----------------------------%s--\r\n\r\n\r\n"),
key,key,key,key,key,key);

pFile->AddRequestHeaders(_T("Content-Length: 581"));
pFile->AddRequestHeaders(_T("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, "
"application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"));
pFile->AddRequestHeaders(_T("Accept-Language: zh-cn\r\n"));
pFile->AddRequestHeaders(strHeadData);
pFile->AddRequestHeaders(_T("Referer: http://bbs.zynews.com/showtopic-8717.aspx"));

ret = pFile->SendRequest(NULL,0,(LPVOID)strFormatData.GetBuffer(),strFormatData.GetLength());
if(ret)
{
ret = pFile->QueryInfoStatusCode(dwRet);
TRACE("Post dwRet = %d\n",dwRet);

CString a;
FILE *fp = fopen("c:\\post.html","w+");
if(fp == NULL) return;
while(pFile->ReadString(a))
{
fprintf(fp,"%s",a);
}
fclose(fp);
}
pFile->Close();
session.Close();

}
catch(...)
{
}
...全文
126 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jobsccnu 2010-04-01
  • 打赏
  • 举报
回复
你用sniffer软件就很容易截获到了。
小生我怕怕 2010-03-04
  • 打赏
  • 举报
回复
兄弟 我不能帮你解决问题但是我可以帮你顶啊
顶~~~~~
顶~~~~
小生我怕怕 2010-03-04
  • 打赏
  • 举报
回复
CString strFormatData = "username=joyswgood&password=ghygood1&question=0&answer=&expires=43200&templateid=0&login=%E7%99%BB%E5%BD%95";//for 中原网

楼主这个数据怎么获取的啊 ? 我想写个自动登录的程序,pay.163.com 可是strFormatData找不对 ,HTML不熟悉。。
楼主~帅哥~
帮我看看 pay.163.com 这个网站的strFormatData 得怎么写啊
谢谢~~
jobsccnu 2010-03-03
  • 打赏
  • 举报
回复
进来的哥们都有分啊,先到先得。

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧