有兴趣的进来看看,用wininet登陆网站提交表单的问题

西山小月 2008-07-18 09:55:33
我用ieHttpHeader抓到的数据是这样的:


POST /kaoqin/login.do 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, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://10.17.254.37:8000/kysc/login/login.jsp
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; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Content-Length: 45
Connection: Keep-Alive
Cache-Control: no-cache

sn=&pass=&sn2=1234567890&pass2=1234567890

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573; Path=/kaoqin
Content-Type: text/html;charset=GB18030
Content-Length: 7613
Date: Thu, 17 Jul 2008 09:13:42 GMT

GET /kaoqin/js/keydown.js HTTP/1.1
Accept: */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
If-Modified-Since: Fri, 11 Jul 2008 08:13:10 GMT
If-None-Match: W/"3204-1215763990968"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Date: Thu, 17 Jul 2008 09:13:42 GMT

GET /kaoqin/picture/first-dbbutton.png HTTP/1.1
Accept: */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
If-Modified-Since: Fri, 11 Jul 2008 08:13:12 GMT
If-None-Match: W/"4746-1215763992484"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Date: Thu, 17 Jul 2008 09:13:42 GMT

GET /kaoqin/picture/first-ybbutton2.png HTTP/1.1
Accept: */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
If-Modified-Since: Fri, 11 Jul 2008 08:13:12 GMT
If-None-Match: W/"4617-1215763992500"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

GET /kaoqin/kaoqin/login/defalue/first_top.jsp 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, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Date: Thu, 17 Jul 2008 09:13:42 GMT

GET /kaoqin/picture/first-bottom2.png HTTP/1.1
Accept: */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
If-Modified-Since: Fri, 11 Jul 2008 08:13:12 GMT
If-None-Match: W/"14086-1215763992484"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=GB18030
Content-Length: 2348
Date: Thu, 17 Jul 2008 09:13:42 GMT

HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Date: Thu, 17 Jul 2008 09:13:42 GMT

GET /kaoqin/picture/first-user.png HTTP/1.1
Accept: */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
If-Modified-Since: Fri, 11 Jul 2008 08:13:12 GMT
If-None-Match: W/"10786-1215763992484"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Date: Thu, 17 Jul 2008 09:13:42 GMT

GET /kaoqin/tree.do?flag=0 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, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

GET /kaoqin/kaoqin/login/defalue/main.jsp 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, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=GB18030
Content-Length: 5111
Date: Thu, 17 Jul 2008 09:13:42 GMT

GET /kaoqin/picture/first-left.png HTTP/1.1
Accept: */*
Referer: http://10.17.254.37:8000/kaoqin/login.do
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
If-Modified-Since: Fri, 11 Jul 2008 08:13:12 GMT
If-None-Match: W/"6194-1215763992484"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Date: Thu, 17 Jul 2008 09:13:42 GMT

GET /kaoqin/kaoqin/login/defalue/style_hr/css1.css HTTP/1.1
Accept: */*
Referer: http://10.17.254.37:8000/kaoqin/kaoqin/login/defalue/first_top.jsp
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: 10.17.254.37:8000
Connection: Keep-Alive
Cookie: JSESSIONID=3452B0673A8B08988D4C304786C35573

HTTP/1.1 304 Not Modified
Server: Apache-Coyote/1.1
Date: Thu, 17 Jul 2008 09:13:42 GMT


我用httpsendrequest发送post数据时
返回失败,不知什么原因。
高手能不能给出个代码看看啊???
...全文
205 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
budongsayyoume 2011-03-15
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 slek 的回复:]
ding
[/Quote]
我也遇到这个问题了 没办法解决
西山小月 2008-08-29
  • 打赏
  • 举报
回复
ding
西山小月 2008-08-03
  • 打赏
  • 举报
回复
up
西山小月 2008-08-02
  • 打赏
  • 举报
回复
再顶一次吧
西山小月 2008-07-29
  • 打赏
  • 举报
回复
西山小月 2008-07-28
  • 打赏
  • 举报
回复
来人看看啊
西山小月 2008-07-25
  • 打赏
  • 举报
回复
诺大个csdn,就没人会了吗???
西山小月 2008-07-24
  • 打赏
  • 举报
回复
up
西山小月 2008-07-21
  • 打赏
  • 举报
回复

CString strHeaders = _T( "Content-Type: application/x-www-form-urlencoded");
CString strFormData = _T( "sn=&pass=&sn2=230602198004164016&pass2=111111");
CInternetSession session("My Session");
CHttpConnection *pServer = NULL;
CHttpFile *pFile = NULL;
CString ServerName = "http://10.17.254.37";
INTERNET_PORT nPort = 8000;
DWORD retcode;
char outBuff[300] = "sn=&pass=&sn2=230602198004164016&pass2=111111"; //I have test this with my loginname and password
try
{
pServer = session.GetHttpConnection(_T("http://10.17.254.37"), 0, 8000);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, _T("/kysc/login/login.jsp"));

pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
pFile->QueryInfoStatusCode(retcode);
// you can read from the file after this......I've just left it out.
for(int i=0; i<10; i++) //read ten line of returned HTML,you need to edit this to use the result
{
CString smsg;
pFile->ReadString(smsg);
AfxMessageBox(smsg);
}
DWORD dwlen=pFile->GetLength();
char buf[1024];
DWORD dwread=pFile->Read(buf,1024);
}
catch(CInternetException *e)
{
char c[1024] = {0};
e->GetErrorMessage(c, 100000, NULL);
AfxMessageBox(c);
};
delete pFile;
delete pServer;
session.Close();
}


pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
处返回错误:无法解析的服务器地址
怎么回事啊????
西山小月 2008-07-21
  • 打赏
  • 举报
回复
post代码如下:



CString strHeaders = _T( "Content-Type: application/x-www-form-urlencoded");
CString strFormData = _T( "sn=&pass=&sn2=230602198004164016&pass2=111111");
CInternetSession session("My Session");
CHttpConnection *pServer = NULL;
CHttpFile *pFile = NULL;
CString ServerName = "http://10.17.254.37";
INTERNET_PORT nPort = 8000;
DWORD retcode;
char outBuff[300] = "sn=&pass=&sn2=230602198004164016&pass2=111111"; //I have test this with my loginname and password
try
{
pServer = session.GetHttpConnection(_T("http://10.17.254.37"), 0, 8000);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, _T("/kysc/login/login.jsp"));

pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
pFile->QueryInfoStatusCode(retcode);
// you can read from the file after this......I've just left it out.
for(int i=0; i<10; i++) //read ten line of returned HTML,you need to edit this to use the result
{
CString smsg;
pFile->ReadString(smsg);
AfxMessageBox(smsg);
}
DWORD dwlen=pFile->GetLength();
char buf[1024];
DWORD dwread=pFile->Read(buf,1024);
}
catch(CInternetException *e)
{
char c[1024] = {0};
e->GetErrorMessage(c, 100000, NULL);
AfxMessageBox(c);
};
delete pFile;
delete pServer;
session.Close();
}



pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
处返回错误:无法解析的服务器地址
是怎么回事啊?????
西山小月 2008-07-21
  • 打赏
  • 举报
回复
代码如下


CInternetSession session("My Session");
CHttpConnection *pServer = NULL;
CHttpFile *pFile = NULL;
CString ServerName = "http://10.17.254.37";
INTERNET_PORT nPort = 8000;
DWORD retcode;
char outBuff[300] = "sn=&pass=&sn2=123456&pass2=111111"; //I have test this with my loginname and password
try
{
pServer = session.GetHttpConnection(ServerName,nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,"http://10.17.254.37/kysc/login/login.jsp",NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
pFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
pFile->AddRequestHeaders("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*");
pFile->SendRequest(NULL, 0, outBuff, strlen(outBuff)+1);
pFile->QueryInfoStatusCode(retcode);
// you can read from the file after this......I've just left it out.
for(int i=0; i<10; i++) //read ten line of returned HTML,you need to edit this to use the result
{
CString smsg;
pFile->ReadString(smsg);
AfxMessageBox(smsg);
}
DWORD dwlen=pFile->GetLength();
char buf[1024];
DWORD dwread=pFile->Read(buf,1024);
}
catch (CInternetException * e)
{
char c[1024] = {0};
e->GetErrorMessage(c, 100000, NULL);
AfxMessageBox(c);
};
delete pFile;
delete pServer;
session.Close();
}



在pFile->SendRequest(NULL, 0, outBuff, strlen(outBuff)+1); 这句的时候出错,返回的错误是无法解析的服务器名称或地址。

有高人吗?能否指点一下!!!
感激不尽!!!

Amuro1987218 2008-07-18
  • 打赏
  • 举报
回复
sn=&pass=&sn2=1234567890&pass2=1234567890

你POST 代码呢
marine8086 2008-07-18
  • 打赏
  • 举报
回复
把你发送的时候,也抓下来,看看你都发的是什么数据,对比一下。

16,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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