关于网友提出的“ 新手写qq注册器遇到的问题CHttpfile”问题疑问,本网通过在网上对“ 新手写qq注册器遇到的问题CHttpfile”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 新手写qq注册器遇到的问题CHttpfile
描述: 1.Post中文,在vc++中需要urlencode吗(我用了urlencode "post字符" 也不行)?
2.COOKIE值好像不需要手动添加,CHttpConnection似乎已经记录了(好像在使用Ie一样),是这样吗?
在输入错误的验证码后,返回结果提示"输入验证码错误";
输入正确的验证码后,返回提示"没有填写必要的表单";(这个说名中文的验证吗已经发出去了呀)
Post文字:
Validatecode=一子饶迷地吵大年&Age=27&NickName=vyciht&Passwd=ojmamafs&Country=中华人民共和国&CityNo=广州&Province=广东&Sex=女&RegisterType=1&public=0
字段是正确的,我用vc#写的可以注册完成,vc#中需要urlencode
void CQQDlg::OnBnClickedReg()
{
BOOL bresult=TRUE;
char szpcode[16+1];
string code;
GetDlgItemText(IDC_CODE,szpcode,16+1);
code=szpcode;
if(code.length()<16)
{
MessageBox("验证码输入错误!");
return;
}
SetUserInfo(code);
//STEP_1 用GET方式获取COOKIE_1
CInternetSession pcis;
CHttpConnection* pHttpc />
CHttpFile* pHttpfile=pHttpconn->OpenRequest("GET",REGSTEP1URL.c_str());
string header="Referer: HTTP://"+REGSERVER+REGSTEP1URL;
pHttpfile->AddRequestHeaders(header.c_str());
pHttpfile->SendRequest();
pHttpfile->Close();
pHttpconn->Close();
delete pHttpfile;
delete pHttpconn;
//STEP_2 用POST 方式发送数据
CString strPost;
strPost.Append("Validatecode=");
strPost.Append(UserInfo.ValidateCode.c_str());
strPost.Append("&Age=");
strPost.Append(IntToCString(UserInfo.Age));
strPost.Append("&NickName=");
strPost.Append(UserInfo.NickName.c_str());
strPost.Append("&Passwd=");
strPost.Append(UserInfo.UserPass.c_str());
strPost.Append("&Country=");
strPost.Append(UserInfo.Country.c_str());
strPost.Append("&CityNo=");
strPost.Append(UserInfo.City.c_str());
strPost.Append("&Province=");
strPost.Append(UserInfo.Province.c_str());
strPost.Append("&Sex=");
strPost.Append(UserInfo.Sex.c_str());
strPost.Append("&RegisterType=1&public=0");
TRACE(strPost+"\r\n");
CHttpConnection* pHttpc />
CHttpFile* pHttpfile1=pHttpconn1->OpenRequest("POST",REGSTEP2URL.c_str());
//pHttpfile1->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded\r\n");//这句使用和不使用都返回一样的结果,加Content-Length也是一样的结果
pHttpfile1->SendRequestEx(strPost.GetLength());
pHttpfile1->WriteString(strPost);
pHttpfile1->EndRequest();
CString l;
while(pHttpfile1->ReadString(l))
{
TRACE(l+"\n");
//page_fail2.htm 验证码错误
//
}
pHttpfile1->Close();
pHttpconn1->Close();
pcis.Close();
delete pHttpfile1;
delete pHttpconn1;
}
void CQQDlg::OnBnClickedRe()
{
GetCodeImg();
SetDlgItemText(IDC_CODE,"");
}
void CQQDlg::SetUserInfo(string code)
{
srand((unsigned)time(NULL));
//NickName;
UserInfo.NickName="";
for(int i=0;i<6;i++)
{
UserInfo.NickName+=ARRCHAR[GetRandomNum(25)];
}
//UserPass;
UserInfo.UserPass="";
for(int i=0;i<8;i++)
{
UserInfo.UserPass+=ARRCHAR[GetRandomNum(25)];
}
UserInfo.Age=GetRandomNum(20)+20;
UserInfo.Country="中华人民共和国";
UserInfo.City="广州";
UserInfo.Province="广东";
UserInfo.Sex=(GetRandomNum(2)>1)?"男":"女";
UserInfo.ValidateCode=code;
}
int CQQDlg::GetRandomNum(int max)
{
return (int)(max*(double)rand()/(double)RAND_MAX);
}
CString CQQDlg::UrlEncode(string str)
{
DWORD len,maxlen;
len=100;
maxlen=100;
char buf[100];
BOOL bresult=AtlEscapeUrl(str.c_str(),buf,&len,maxlen);
ASSERT(bresult);
CString stren(buf,len-1);//-1 是去掉缓冲区中的0
return stren;
}
以上介绍了“ 新手写qq注册器遇到的问题CHttpfile”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3152927.html