关于POST提交表单的问题?

Eleven 2008-03-06 03:33:56
这是个html页面,网站:http://www.ip138.com:8080/search.asp
在VC中我如何编写代码获取返回的信息,例如在对话框模式下,一个Edit,一个Button,在一个Edit中输入手机号码,点击Button后要求返回查询手机号码的信息!
这下面的该论坛的一个达人写的一个方法:
void CCMDlg::Post(CString &csResponse,const char *szServer,INTERNET_PORT &nPort,const char *szObject,const char *szData,DWORD &dwHttpStatus,BOOL bAutoRedirect)
{
//参数说明:
/*
csResponse:返回的数据
szServer:服务器
nPort:端口
szObject:URI
szData:正文内容
dwHttpStatus:状态码
bAutoRedirect:是否自动转向
*/
CInternetSession *pSession=NULL;
CHttpConnection *pConnection=NULL;
CHttpFile *pHttpFile=NULL;

try{
pSession=new CInternetSession(NULL,1,INTERNET_OPEN_TYPE_PRECONFIG);
pConnection=pSession->GetHttpConnection(szServer,nPort,NULL,NULL);
DWORD dwFlag=INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE;

if(!bAutoRedirect)
{
dwFlag=dwFlag|INTERNET_FLAG_NO_AUTO_REDIRECT;
}
pHttpFile=pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,szObject,szServer,1,NULL,NULL,dwFlag);

pHttpFile->AddRequestHeaders("Content-Type: appliction/x-www-form-urlencoded",HTTP_ADDREQ_FLAG_ADD_IF_NEW,-1L);

pHttpFile->SendRequest(NULL,0,(LPVOID)szData,strlen(szData));
if(pHttpFile)
{
if(pHttpFile->QueryInfoStatusCode(dwHttpStatus)!=0)
{
//dwHttpStatus=200;
if(dwHttpStatus<400)
{
int nRead=0;
LPSTR pBuffer=new char[1024];
do{
nRead=pHttpFile->Read(pBuffer,1023);
if(nRead!=0)
{
pBuffer[nRead]=0;
csResponse+=pBuffer;
}
}while(nRead!=0);
if(pBuffer)
{
delete pBuffer;
pBuffer=NULL;
}
}
}
}
}catch(CInternetException *e)
{
e->Delete();
}
catch(...)
{

}
if(pHttpFile!=NULL)
{
pHttpFile->Close();
delete pHttpFile;
}
if(pConnection!=NULL)
{
pConnection->Close();
delete pConnection;
}
if(pSession!=NULL)
{
pSession->Close();
delete pSession;
}
}

我在下面的这个函数中响应按钮点击事件
void CCMDlg::OnBnClickedOk()
{

CString csResponse;
CString sPhone;
GetDlgItemText(IDC_EDIT1,sPhone);
INTERNET_PORT nPort=8080;
DWORD dwRes=0;
//AfxMessageBox(sPhone);
CString strData="mobileform:";
strData+=sPhone;
Post(csResponse,"www.ip138.com",nPort,"search.asp",strData,dwRes,TRUE);
//AfxMessageBox(csResponse);
SetDlgItemText(IDC_EDIT1,csResponse);
}
...全文
544 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
僵哥 2008-03-07
  • 打赏
  • 举报
回复
楼上的兄弟你说的这个服务器,好象还不检测Cookie,可以直接发送表单数据是什么意思,能否详细解释一下,不胜感激!
============
搜索一下什么是网页当中的“Cookie”就知道了。
Eleven 2008-03-07
  • 打赏
  • 举报
回复
楼上的兄弟你说的这个服务器,好象还不检测Cookie,可以直接发送表单数据是什么意思,能否详细解释一下,不胜感激!
Eleven 2008-03-07
  • 打赏
  • 举报
回复
先试一下,不管成不成功,都要感谢楼上的兄弟!
僵哥 2008-03-07
  • 打赏
  • 举报
回复
使用socket连接上www.ip138.com的8080端口,直接发送数据:
POST /search.asp HTTP/1.1
Accept: */*
Referer: http://www.ip138.com/
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0
Host: www.ip138.com:8080
Content-Length: 32
Connection: Keep-Alive
Cache-Control: no-cache

action=mobile&mobile=[手机号]
僵哥 2008-03-07
  • 打赏
  • 举报
回复
这个服务器,好象还不检测Cookie,可以直接发送表单数据。
僵哥 2008-03-07
  • 打赏
  • 举报
回复
connect www.ip138.com:80
locate HTTP Head [Set-Cookie]
[Cokie-string-text]=Cookie

connect www.ip138.com:8080
send Text:
POST /search.asp HTTP/1.1
Accept: */*
Referer: http://www.ip138.com/
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0
Host: www.ip138.com:8080
Content-Length: 32
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: [Cokie-string-text]

action=mobile&mobile=1**********

recv...
greatws 2008-03-06
  • 打赏
  • 举报
回复
不知道你要问什么,而且http://www.ip138.com:8080/search.asp 打不开

18,356

社区成员

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

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