请教用wininet提交POST表单不成功的问题?

cyfage 2010-11-09 09:00:50
最近在学习Wininet,结果冒出来很多奇怪的问题,比如像这个,不管怎么POST都无法成功,特地来请教各位达人:

环境:
在下在本机使用Apache2.5.10+PHP+MYSQL架设了一个服务器环境(WindowsXP),然后安装了最新版本的Discuz论坛,局域网环境下安装和调试貌似正常,可以任意访问注册使用等。

报文:
我用ieHTTPHeaders2.0抓取了Discuz点击注册时的报文,然后编写如下:

CString TempHead;
TempHead += "POST /member.php?mod=register&inajax=1 HTTP/1.1\r\n";
TempHead += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";
TempHead += "Referer: http://127.0.0.1/member.php?mod=register\r\n";
TempHead += "Accept-Language: zh-cn\r\n";
TempHead += "Content-Type: multipart/form-data; boundary=---------------------------7da9c24180124\r\n";
TempHead += "UA-CPU: x86\r\n";
TempHead += "Accept-Encoding: gzip, deflate\r\n";
TempHead += "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)\r\n";
TempHead += "Host: 127.0.0.1\r\n";
TempHead += "Content-Length: 879\r\n";
TempHead += "Connection: Keep-Alive\r\n";
TempHead += "Cache-Control: no-cache\r\n";
TempHead += "Cookie: zkzD_2132_sid=41Ymwi; zkzD_2132_lastvisit=1289185316; zkzD_2132_lastact=1289188945%09forum.php%09ajax; zkzD_2132_onlineusernum=2; zkzD_2132_sendmail=1\r\n";
TempHead += "-----------------------------7da9c24180124\r\n";
TempHead += "Content-Disposition: form-data; name='regsubmit'\r\n";
TempHead += "yes\r\n";
TempHead += "-----------------------------7da9c24180124\r\n";
TempHead += "Content-Disposition: form-data; name='formhash'\r\n";
TempHead += "5968679d\r\n";
TempHead += "-----------------------------7da9c24180124\r\n";
TempHead += "Content-Disposition: form-data; name='referer'\r\n";
TempHead += "http://127.0.0.1/\r\n";
TempHead += "-----------------------------7da9c24180124\r\n";
TempHead += "Content-Disposition: form-data; name='activationauth'\r\n";
TempHead += "-----------------------------7da9c24180124\r\n";
TempHead += "Content-Disposition: form-data; name='username'\r\n";
TempHead += "fuck04\r\n";
TempHead += "-----------------------------7da9c24180124\r\n";
TempHead += "Content-Disposition: form-data; name='password'\r\n";
TempHead += "123456\r\n";
TempHead += "-----------------------------7da9c24180124\r\n";
TempHead += "Content-Disposition: form-data; name='password2'\r\n";
TempHead += "123456\r\n";
TempHead += "-----------------------------7da9c24180124\r\n";
TempHead += "Content-Disposition: form-data; name='email'\r\n";
TempHead += "1@1.com\r\n";
TempHead += "-----------------------------7da9c24180124--\r\n";


发送部分:

wPort = 80;
m_httpConnection = m_inernetSession.GetHttpConnection("127.0.0.1", wPort);
m_httpfile = m_httpConnection->OpenRequest(m_httpConnection->HTTP_VERB_POST, "/member.php?mod=register");
if (NULL == m_httpfile)
{
return;
}

m_httpfile->AddRequestHeaders(TempHead);
bool SendRes = m_httpfile->SendRequest();
if (false == SendRes)
{
Say("SendRequest Error");
return;
}
else
{
m_Sended = true;
}

DWORD Ret = 0;
m_httpfile->QueryInfoStatusCode(Ret);
//400-499 Request Error
//500-599 Sever Error
char Temp[100];
sprintf(Temp, "The Request Status is %ld", Ret);
Say(Temp);

QueryInfoStatusCode查询的返回值始终为200,按理说应该是正确投递了吧?

可奇怪的是为什么返回的不是注册成功或失败的内容,而是一个无法理解的网页呢?
接收部分的代码:

CTestHttpDlg *InP = reinterpret_cast<CTestHttpDlg*>(lpParam);

while (1)
{
Sleep(10);

if (true == InP->m_Sended)
{
DWORD Lenth = InP->m_httpfile->GetLength();
bool Res = InP->m_httpfile->Read(InP->m_RecvBuff, 62999);
/*bool Res = InP->m_httpfile->Read(InP->m_RecvBuff, Lenth);*/
if (true == Res)
{
InP->Say(InP->m_RecvBuff);
}
else
{
InP->Say("InternetReadFile Error");
}
InP->m_Sended = false;
}
}


返回的内容如图所示:


我完全不明白,返回一个这样的网页是什么意思呢?完全无法判断到底注册成功了没——从数据库来看肯定没有注册成功,可不成功的问题出在哪里呢?

这里是完整的工程文件:
http://www.eyerecover.com/TestHttp.rar

希望有达人能不吝指教一下,谢谢!
...全文
743 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
LuciferStar 2012-10-15
  • 打赏
  • 举报
回复
CInternetSession * session;//全局
const int nTimeOut = 3000;
session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, nTimeOut); //重试之间的等待延时
session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 3); //重试次数

//////以上是session的准备

pConnection=session.GetHttpConnection(server,port);//请求

pConnection->Close ();
delete pConnection;
pConnection=NULL;//请求结束后关闭Connection,但不关闭session

此时,可以进行更多请求:

pConnection=session.GetHttpConnection(server,port);//请求

pConnection->Close ();
delete pConnection;
pConnection=NULL;//请求结束后关闭Connection,但不关闭session

当所有请求结束后
session->Close();

期间不需要如上面那样自己分析cookie数据了,因为session会自动保存和转发。
cyfage 2010-11-11
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 luciferstar 的回复:]
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,action,NULL,1,NULL,NULL,INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->Send……
[/Quote]

非常感谢,我原来一直不知道要用QueryInfo来取得Header的。

现在成功取得了COOKIE,我试着进行自动登录,还是没有成功,也不知道为什么……

TempHead += "POST /member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&inajax=1 HTTP/1.1\r\n";
TempHead += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";
TempHead += "Referer: http://127.0.0.1/member.php?mod=logging&action=login\r\n";
TempHead += "Accept-Language: zh-cn\r\n";
TempHead += "Content-Type: application/x-www-form-urlencoded\r\n";
TempHead += "UA-CPU: x86\r\n";
TempHead += "Accept-Encoding: gzip, deflate\r\n";
TempHead += "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)\r\n";
TempHead += "Host: 127.0.0.1\r\n";
TempHead += "Content-Length: 106\r\n";
TempHead += "Connection: Keep-Alive\r\n";
TempHead += "Cache-Control: no-cache\r\n";
TempHead += LoginCookie; //加入翻译好的COOKIE
TempHead += "\r\n";
TempHead += "fastloginfield=username&username=fuck05&password=123456&quickforward=yes&handlekey=ls&questionid=0&answer=\r\n";

wPort = 80;
m_httpConnection = m_inernetSession.GetHttpConnection("127.0.0.1", wPort);
m_httpfile = m_httpConnection->OpenRequest(m_httpConnection->HTTP_VERB_POST, "/member.php?mod=logging&action=login");
if (NULL == m_httpfile)
{
return;
}

m_httpfile->AddRequestHeaders(TempHead);
bool SendRes = m_httpfile->SendRequest();


不过暂时先算了,结了这个帖子吧,无论如何,非常感谢你。
LuciferStar 2010-11-11
  • 打赏
  • 举报
回复
原来那个pFile在Close后要delete的,害我查了半天内存泄露。
LuciferStar 2010-11-11
  • 打赏
  • 举报
回复
竟然不能连续回超过3帖:(
邮箱PM我?我把整个项目发给你。


void CMyRegDlg::OnBnClickedButton1()//get cookie
{
// TODO: 在此添加控件通知处理程序代码
//构建登陆表单数据

char *action="/d/upload/";
char *headers="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\r\n"
"Accept-Language: zh-cn\r\n"
//"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n"
"Host: 192.168.0.21\r\n"
"Connection: Keep-Alive\r\n\r\n";

CString szHeaders(headers);
// szHeaders=headers;//.Format (headers,nReadLength,sid);

CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,action,NULL,1,NULL,NULL,INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->SendRequest(szHeaders,NULL,NULL);
szHeaders.ReleaseBuffer ();
CString header("");//获取登陆结果中header
pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF,header,0);
pFile->Close();
delete pFile;
int i=header.Find ("Set-Cookie: ");
if(i>=0)
{
i+=12;
cookie1_value=header.Mid ( i,header.Find (";",i)-i);
int j=header.Find ("Set-Cookie: ",i);
if(j>=0)
{
j+=12;
cookie2_value=header.Mid (j,header.Find (";",j)-j);
}
}
header.ReleaseBuffer ();
UpdateData(FALSE);//更新

}

void CMyRegDlg::OnBnClickedButton2()//get formhash
{
// TODO: 在此添加控件通知处理程序代码
int nReadLength =0;
//构建登陆表单数据

char *action="/d/upload/register.php?infloat=yes&handlekey=register&inajax=1&ajaxtarget=fwin_content_register";
char *headers="Accept: */*\r\n"
"Accept-Language: zh-cn\r\n"
"Referer: http://127.0.0.1/d/upload/\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n"
"Host: 127.0.0.1\r\n"
"Connection: Keep-Alive\r\n"
"Cookie: %s\r\n\r\n";

CString szHeaders;
szHeaders.Format (headers,cookie1_value,cookie2_value);

CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,action,NULL,1,NULL,NULL,INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->SendRequest(szHeaders,NULL,NULL);
szHeaders.ReleaseBuffer ();

CString data("");//获取登陆结果页面
char szBuff[1025];
while(1)
{
nReadLength = pFile->Read(szBuff, 1024);
if(nReadLength==0) break;
szBuff[nReadLength]='\0';
data=data+szBuff;
}
pFile->Close();
delete pFile;

int i=data.Find ("formhash");
if(i>=0)
{
i+=17;
formhash_value=data.Mid ( i,data.Find ("\"",i)-i);
UpdateData(NULL);
}
data.ReleaseBuffer ();

}

void CMyRegDlg::OnBnClickedButton3()//go to register
{
// TODO: 在此添加控件通知处理程序代码
//构建登陆表单数据

char *action="/d/upload//register.php?regsubmit=yes&inajax=1";
char *headers="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\r\n"
"Referer: http://127.0.0.1/d/upload/index.php\r\n"
"Accept-Language: zh-cn\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
// "Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n"
"Host: 127.0.0.1\r\n"
"Content-Length: %d\r\n"
"Connection: Keep-Alive\r\n"
"Cache-Control: no-cache\r\n"
"Cookie: %s; %s\r\n";

char *form1="formhash=%s";
char *form2="&referer=http%3A%2F%2F127.0.0.1%2Fd%2Fupload%2findex.php&handlekey=register&activationauth=&username=test2&password=test&password2=test&email=test2@mail.com®submit=%CC%E1%BD%BB";
CString formdata;
formdata.Format (form1,formhash_value);
formdata.Append (form2);
int nReadLength=formdata.GetLength ();

CString szHeaders;
szHeaders.Format (headers,nReadLength,cookie1_value,cookie2_value);

CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,action,NULL,1,NULL,NULL,INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->SendRequest(szHeaders,(LPVOID)formdata.GetBuffer (),nReadLength);

szHeaders.ReleaseBuffer ();
formdata.ReleaseBuffer ();

CString data("");//获取登陆结果页面
char szBuff[1025];
while(1)
{
nReadLength = pFile->Read(szBuff, 1024);
if(nReadLength==0) break;
szBuff[nReadLength]='\0';
data=data+szBuff;
}
pFile->Close();
delete pFile;
int i=data.Find ("CDATA[");
// CDATA[该用户名已经被注册]
if(i>=0)
{
i+=6;
AfxMessageBox(data.Mid (i,data.Find ("]",i)-i));
}
//if(data.Find ("该用户名已经被注册")) AfxMessageBox("已经存在!");
m_data.SetWindowTextA (data);
data.ReleaseBuffer ();

}

LuciferStar 2010-11-10
  • 打赏
  • 举报
回复
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,action,NULL,1,&types,NULL,INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);

是这个参数:INTERNET_FLAG_NO_AUTO_REDIRECT
这个是禁止自动跳转的。
LuciferStar 2010-11-10
  • 打赏
  • 举报
回复
跳转直接跳过,获取了跳转后的页面,我上次也遇到过。
忘记是怎么解决的了,跟发送的参数有关,我再找找:)
cyfage 2010-11-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 luciferstar 的回复:]
对了,那个formhash,在这个页面获取:
GET /register.php?infloat=yes&handlekey=register&inajax=1&ajaxtarget=fwin_content_register HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Referer: http://127.0.0.1/……
[/Quote]

[Quote=引用 14 楼 luciferstar 的回复:]
对了,那个formhash,在这个页面获取:
GET /register.php?infloat=yes&handlekey=register&inajax=1&ajaxtarget=fwin_content_register HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Referer: http://127.0.0.1/……
[/Quote]

再一次感谢……
不过我有一个非常疑惑的地方,为什么我的请求从来没有返回过如你所贴的那些响应呢?我GET什么都是返回那一处的网页内容:
比如你说的打开主页有个跳转什么的,我完全没接收到过,我打开主页只能看到返回一个似乎是完整的主页页面内容,我是这样发送GET请求的,请问这样有什么问题吗?


CString TempHead;
//请求一个页面的报文
TempHead += "GET HTTP/1.1\r\n";
TempHead += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";
TempHead += "Accept-Language: zh-cn\r\n";
TempHead += "Accept-Encoding: gzip, deflate\r\n";
TempHead += "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)\r\n";
TempHead += "Host: 192.168.1.82\r\n";
TempHead += "Connection: Keep-Alive\r\n";

wPort = 80;
m_httpConnection = m_inernetSession.GetHttpConnection("192.168.1.82", wPort);
m_httpfile = m_httpConnection->OpenRequest(m_httpConnection->HTTP_VERB_POST, "");
if (NULL == m_httpfile)
{
return;
}

m_httpfile->AddRequestHeaders(TempHead);
bool SendRes = m_httpfile->SendRequest();
if (false == SendRes)
{
Say("SendRequest Error");
return;
}
else
{
m_Sended = true;
}

DWORD Ret = 0;
m_httpfile->QueryInfoStatusCode(Ret);
//400-499 Request Error
//500-599 Sever Error
char Temp[100];
sprintf(Temp, "The Request Status is %ld", Ret);
Say(Temp);
LuciferStar 2010-11-10
  • 打赏
  • 举报
回复
对了,那个formhash,在这个页面获取:
GET /register.php?infloat=yes&handlekey=register&inajax=1&ajaxtarget=fwin_content_register HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Referer: http://127.0.0.1/index.php
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Host: 127.0.0.1
Connection: Keep-Alive
Cookie: Q75_onlineusernum=1; Q75_sid=n6XkNK

LuciferStar 2010-11-10
  • 打赏
  • 举报
回复
打开主页面,有一个跳转:
HTTP/1.1 301 Moved Permanently

在跳转后,有如下页面,在这个页面,有Cookie投递。
HTTP/1.1 200 OK
Date: Wed, 10 Nov 2010 00:16:43 GMT
Server: Apache/2.0.59 (Win32) PHP/5.2.6
X-Powered-By: PHP/5.2.6
Set-Cookie: Q75_sid=n6XkNK; expires=Wed, 17-Nov-2010 00:16:43 GMT; path=/; httponly
Set-Cookie: Q75_onlineusernum=1; expires=Wed, 10-Nov-2010 00:21:43 GMT; path=/
Content-Length: 7406
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/html

得到cookie后,开始执行注册:
POST /register.php?regsubmit=yes&inajax=1 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
Referer: http://127.0.0.1/index.php
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Host: 127.0.0.1
Content-Length: 199
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: Q75_onlineusernum=1; Q75_sid=n6XkNK

formhash=e5e1cd80&referer=http%3A%2F%2F127.0.0.1%2Findex.php&handlekey=register&activationauth=&username=test2&password=test&password2=test&email=test2@mail.com®submit=%CC%E1%BD%BB

那个formhash,你得从上一页面得到,提交后得到如下结果:
HTTP/1.1 200 OK
Date: Wed, 10 Nov 2010 00:24:56 GMT
Server: Apache/2.0.59 (Win32) PHP/5.2.6
X-Powered-By: PHP/5.2.6
Set-Cookie: Q75_loginuser=deleted; expires=Tue, 10-Nov-2009 00:24:55 GMT; path=/
Set-Cookie: Q75_activationauth=deleted; expires=Tue, 10-Nov-2009 00:24:55 GMT; path=/
Expires: -1
Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0
Pragma: no-cache
Content-Length: 519
Keep-Alive: timeout=15, max=91
Connection: Keep-Alive
Content-Type: application/xml; charset=gbk

<?xml version="1.0" encoding="gbk"?><root><![CDATA[<script type="text/javascript" onload="1">if(document.body.stat) document.body.stat('register_succeed', 'register.php');
display('main_messaqge');
display('layer_reg');
display('layer_message');
$('messageleft1').innerHTML = '<p>.......... ............</p>';
$('messageright1').innerHTML = '<a href="javascript:;" onclick="location.reload()">..............................</a>';
setTimeout('location.reload()', 3000);
</script>
</div></div>
</div>
]]></root>
LuciferStar 2010-11-10
  • 打赏
  • 举报
回复
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,action,NULL,1,NULL,NULL,INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->SendRequest(szHeaders,(LPVOID)formdata.GetBuffer (),nReadLength);

CString header("");//获取登陆结果中header
pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF,header,0);

CString data("");//获取登陆结果页面
char szBuff[1025];
while(1)
{
nReadLength = pFile->Read(szBuff, 1024);
if(nReadLength==0) break;
szBuff[nReadLength]='\0';
data=data+szBuff;
}
pFile->Close();
LuciferStar 2010-11-10
  • 打赏
  • 举报
回复
下午开会去了,明天我做做看:)
cyfage 2010-11-10
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 luciferstar 的回复:]
INTERNET_FLAG_NO_COOKIES可以去掉。
比较奇怪。看看是否是其他什么地方的问题?
[/Quote]

完整的接收函数:

DWORD CTestHttpDlg::RecvProc(LPVOID lpParam)
{
CTestHttpDlg *InP = reinterpret_cast<CTestHttpDlg*>(lpParam);

while (1)
{
Sleep(10);

if (true == InP->m_Sended)
{
bool Res = InP->m_httpfile->Read(InP->m_RecvBuff, 62999);
if (true == Res)
{
InP->Say(InP->m_RecvBuff);
}
}
}

return 0;
}
cyfage 2010-11-10
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 luciferstar 的回复:]
INTERNET_FLAG_NO_COOKIES可以去掉。
比较奇怪。看看是否是其他什么地方的问题?
[/Quote]
没辙了
不管怎么调试OpenRequest()返回的都是页面;
请教一下,
接收部分是这样读取的吗?

bool Res = InP->m_httpfile->Read(InP->m_RecvBuff, 62999);
if (true == Res)
{
InP->Say(InP->m_RecvBuff);
}

我跟踪这个接收的函数,它第一个接收的就是页面内容,是不是还有其它的读取或者接收方式接收别的内容的?
LuciferStar 2010-11-10
  • 打赏
  • 举报
回复
INTERNET_FLAG_NO_COOKIES可以去掉。
比较奇怪。看看是否是其他什么地方的问题?
cyfage 2010-11-10
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 luciferstar 的回复:]
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,action,NULL,1,&types,NULL,INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);

是这个……
[/Quote]
悲剧……
请问一下,为什么我按照这样写,还是阻止不了网页的跳转呢?

m_httpfile = m_httpConnection->OpenRequest(m_httpConnection->HTTP_VERB_GET,
"",
NULL,
1,
NULL,
NULL,
INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_AUTO_REDIRECT);


返回的依旧是跳转后的页面内容。
cyfage 2010-11-09
  • 打赏
  • 举报
回复
前面怀疑是注册时有没有什么校验,我改成测试登录,发现结果还是一样的,返回200,然后登录没有成功。

这是登录的原始报文:
POST /member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&inajax=1 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://127.0.0.1/
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
Host: 127.0.0.1
Content-Length: 107
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: zkzD_2132_sid=J77K23; zkzD_2132_lastvisit=1289266892; zkzD_2132_lastact=1289270496%09index.php%09; zkzD_2132_sendmail=1; zkzD_2132_onlineusernum=1

fastloginfield=username&username=cyfage&password=8433841&quickforward=yes&handlekey=ls&questionid=0&answer=

这是我程序里写的登录报文:

TempHead += "POST /member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&inajax=1 HTTP/1.1\r\n";
TempHead += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";
TempHead += "Referer: http://127.0.0.1/\r\n";
TempHead += "Accept-Language: zh-cn\r\n";
TempHead += "Content-Type: application/x-www-form-urlencoded\r\n";
TempHead += "UA-CPU: x86\r\n";
TempHead += "Accept-Encoding: gzip, deflate\r\n";
TempHead += "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)\r\n";
TempHead += "Host: 127.0.0.1\r\n";
TempHead += "Content-Length: 107\r\n";
TempHead += "Connection: Keep-Alive\r\n";
TempHead += "Cache-Control: no-cache\r\n";
TempHead += "Cookie: zkzD_2132_sid=J77K23; zkzD_2132_lastvisit=1289266892; zkzD_2132_lastact=1289270496%09index.php%09; zkzD_2132_sendmail=1; zkzD_2132_onlineusernum=1\r\n";
TempHead += "fastloginfield=username&username=fuck05&password=123456&quickforward=yes&handlekey=ls&questionid=0&answer=\r\n";


结果还是一样……郁闷啊
cyfage 2010-11-09
  • 打赏
  • 举报
回复
这是我抓到的IE页面注册的原文(用ieHTTPHeaders抓的),我反复对比之后感觉如果说有什么区别的话,只能是其中每一行那个好像是校验的东西不同了:

POST /member.php?mod=register&inajax=1 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://127.0.0.1/member.php?mod=register
Accept-Language: zh-cn
Content-Type: multipart/form-data; boundary=---------------------------7daab1a1a029a
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
Host: 127.0.0.1
Content-Length: 879
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: zkzD_2132_sid=4537BB; zkzD_2132_lastvisit=1289203271; zkzD_2132_lastact=1289269330%09forum.php%09ajax; zkzD_2132_onlineusernum=1; zkzD_2132_sendmail=1

-----------------------------7daab1a1a029a
Content-Disposition: form-data; name="regsubmit"

yes
-----------------------------7daab1a1a029a
Content-Disposition: form-data; name="formhash"

5968679d
-----------------------------7daab1a1a029a
Content-Disposition: form-data; name="referer"

http://127.0.0.1/
-----------------------------7daab1a1a029a
Content-Disposition: form-data; name="activationauth"


-----------------------------7daab1a1a029a
Content-Disposition: form-data; name="username"

fuck08
-----------------------------7daab1a1a029a
Content-Disposition: form-data; name="password"

123456
-----------------------------7daab1a1a029a
Content-Disposition: form-data; name="password2"

123456
-----------------------------7daab1a1a029a
Content-Disposition: form-data; name="email"

1@1.com
-----------------------------7daab1a1a029a--


“7daab1a1a029a”
这个东西好像每次注册都不一样,请问是这个问题导致提交不成功的吗?如果是的话,该如何处理?
cyfage 2010-11-09
  • 打赏
  • 举报
回复
谢谢楼上各位,抓包的话,因为另外一个对比的是程序,没办法用IE插件,所以我用wildpacketsomnipeek抓的,包里的内容分别如下:

软件注册时的包:
Packet Info
Flags: 0x00000000
Status: 0x00000000
Packet Length: 404
Timestamp: 09:30:04.707192000 11/09/2010
Ethernet Header
Destination: 00:1F:D0:44:8E:67
Source: 00:14:78:84:B5:F6
Protocol Type: 0x0800 IP
IP Header - Internet Protocol Datagram
Version: 4
Header Length: 5 (20 bytes)
Differentiated Services:%00000000
0000 00.. Default
.... ..00 Not-ECT

Total Length: 386
Identifier: 5588
Fragmentation Flags: %010
0.. Reserved
.1. Do Not Fragment
..0 Last Fragment

Fragment Offset: 0 (0 bytes)
Time To Live: 128
Protocol: 6 TCP - Transmission Control Protocol
Header Checksum: 0x5FEE
Source IP Address: 192.168.1.17
Dest. IP Address: 192.168.1.82
TCP - Transport Control Protocol
Source Port: 2069 event-port
Destination Port: 80 http
Sequence Number: 3863657757
Ack Number: 2934053766
TCP Offset: 5 (20 bytes)
Reserved: %0000
TCP Flags: %00011000 ...AP...
0... .... (No Congestion Window Reduction)
.0.. .... (No ECN-Echo)
..0. .... (No Urgent pointer)
...1 .... Ack
.... 1... Push
.... .0.. (No Reset)
.... ..0. (No SYN)
.... ...0 (No FIN)

Window: 65535
TCP Checksum: 0x8037
Urgent Pointer: 0
No TCP Options
HTTP - Hyper Text Transfer Protocol
HTTP Command: POST
URI: /member.php?mod=register
HTTP Version: HTTP/1.1<CR><LF>
User-Agent: TestHttp<CR><LF>
Host: 192.168.1.82<CR><LF>
Content-Length: 0<CR><LF>
Cache-Control: no-cache<CR><LF>
Cookie: zkzD_2132_lastvisit=1289184200; zkzD_2132_sid=GlODgi; zkzD_2132_lastact=1289187829%09home.php%09spacecp; zkzD_2132_auth=b1494hpWzSBNi0yLWDCoNgqzjkPONWmH1r1GvFMHTmSerkPOdT%2BEZjFD%2F2vijXv3CfAepOpy2jjr
eZjd9iVF<CR><LF><CR><LF>
FCS - Frame Check Sequence
FCS: 0x78ABC0E0 Calculated

IE页面注册时发送的包:

Packet Info
Flags: 0x00000000
Status: 0x00000000
Packet Length: 851
Timestamp: 09:33:54.337616000 11/09/2010
Ethernet Header
Destination: 00:1F:D0:44:8E:67
Source: 00:14:78:84:B5:F6
Protocol Type: 0x0800 IP
IP Header - Internet Protocol Datagram
Version: 4
Header Length: 5 (20 bytes)
Differentiated Services:%00000000
0000 00.. Default
.... ..00 Not-ECT

Total Length: 833
Identifier: 15143
Fragmentation Flags: %010
0.. Reserved
.1. Do Not Fragment
..0 Last Fragment

Fragment Offset: 0 (0 bytes)
Time To Live: 128
Protocol: 6 TCP - Transmission Control Protocol
Header Checksum: 0x38DC
Source IP Address: 192.168.1.17
Dest. IP Address: 192.168.1.82
TCP - Transport Control Protocol
Source Port: 2223 rockwell-csp3
Destination Port: 80 http
Sequence Number: 3616623573
Ack Number: 589988239
TCP Offset: 5 (20 bytes)
Reserved: %0000
TCP Flags: %00011000 ...AP...
0... .... (No Congestion Window Reduction)
.0.. .... (No ECN-Echo)
..0. .... (No Urgent pointer)
...1 .... Ack
.... 1... Push
.... .0.. (No Reset)
.... ..0. (No SYN)
.... ...0 (No FIN)

Window: 65535
TCP Checksum: 0xCAAC
Urgent Pointer: 0
No TCP Options
HTTP - Hyper Text Transfer Protocol
HTTP Command: POST
URI: /member.php?mod=register&inajax=1
HTTP Version: HTTP/1.1<CR><LF>
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*<CR><LF>
Referer: http://192.168.1.82/member.php?mod=register<CR><LF>
Accept-Language: zh-cn<CR><LF>
Content-Type: multipart/form-data; boundary=---------------------------7da138363040a<CR><LF>
UA-CPU: x86<CR><LF>
Accept-Encoding: gzip, deflate<CR><LF>
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)<CR><LF>
Host: 192.168.1.82<CR><LF>
Content-Length: 1007<CR><LF>
Connection: Keep-Alive<CR><LF>
Cache-Control: no-cache<CR><LF>
Cookie: zkzD_2132_sid=2BXYsS; zkzD_2132_lastvisit=1289262862; zkzD_2132_lastact=1289266493%09forum.php%09ajax; zkzD_2132_onlineusernum=2; zkzD_2132_sendmail=1<CR><LF><CR><LF>
FCS - Frame Check Sequence
FCS: 0xA7B990F1 Calculated

我看出来不少不同,可不太明白……
因为我软件所写的报文也是按原本IE插件所抓的包几乎完全COPY的呀,为什么发送的时候两者会有这么多不同?
请各位指教一下……
汪宁宇 2010-11-09
  • 打赏
  • 举报
回复
貌似包的格式你没有仔细!

比如CSDN登录前,会有一个KEY,你POST的时候得带上这个KEY
Eleven 2010-11-09
  • 打赏
  • 举报
回复
抓个包比对一下数据是否正确?
加载更多回复(7)

18,356

社区成员

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

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