如题,看过以前一位前辈的文章,大体如下:
UINT Vote(LPVOID)
{
    CInternetSession session;
    theApp.m_nThreads++; //用来记录投票线程数的
    try
    {
        CHttpConnection* pConnection =session.GetHttpConnection("www.onlytest.net"); //网站服务器
        CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,"vote2.asp"); //直接向投票处理页面提交数据
        //下面向提交数据中添加HTTP头,这些可以由网络监视器得到
        pFile->AddRequestHeaders("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*");
        pFile->AddRequestHeaders("Referer: http://www.onlytest.net/vote.htm");
        pFile->AddRequestHeaders("Accept-Language: zh-cn");
        pFile->AddRequestHeaders("Content-Type: multipart/form-data; boundary=---------------------------7d11dc24268052c");
        pFile->AddRequestHeaders("Accept-Encoding: gzip, deflate");
        pFile->AddRequestHeaders("User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
        pFile->AddRequestHeaders("Content-Length: 1351");
        pFile->AddRequestHeaders("Connection: Keep-Alive");
        pFile->AddRequestHeaders("Cache-Control: no-cache");
        //HTTP头后面就应该是真正的数据了,下面theApp.m_strFormData中就是要提交的数据,服务器处理返回的信息在pFile中
        pFile->SendRequest(NULL,0,theApp.m_strFormData.GetBuffer(0),theApp.m_strFormData.GetLength()); //提交所有数据
}
我想问一下:
1、我不知道他说的这个网络监视器是不是什么特殊工具,还有,可以用别的方法得到这些信息吗?
2、他给的代码不用登陆,如果需要登陆,那么得到的信息和需要发送的信息会不同吗?怎么做?

解决方案 »

  1.   

    我用一个小工具得到如下信息,这些够吗?
    GET / HTTP/1.0
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*
    Accept-Language: en-us
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0
    Host: WWW.EYOU.COM
      

  2.   

    http://www.cnblogs.com/ocean/archive/2005/05/07/100445.html
      

  3.   

    我想问,加在AddRequestHeaders中的这些交互信息是怎么得到的?
      

  4.   

    前辈,我得到了那些内容,如下:
    POST /cgi-bin/login 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://www.eyou.com/
    Accept-Language: zh-cn
    Content-Type: application/x-www-form-urlencoded
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
    Host: www.eyou.com
    Content-Length: 78
    Connection: Keep-Alive
    Cache-Control: no-cache
    Cookie: scid=1104977975203713LoginName=zfsfd&Password=7787235&domain=0&imageField.x=0&imageField.y=0
    而后我采用下面的程序,发现没有登陆进去?
    CString strFormData = _T("LoginName=zfsfd&Password=7787235&domain=0&imageField.x=0&imageField.y=0
    ");
        CInternetSession session;
        CHttpConnection* pConnection =session.GetHttpConnection("www.eyou.com"); //网站服务器
        CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,"");
    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 */*");
        pFile->AddRequestHeaders("Referer: http://www.eyou.com/");   
    pFile->AddRequestHeaders("Accept-Language: zh-cn");
    pFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
    pFile->AddRequestHeaders("Accept-Encoding: gzip, deflate");
    pFile->AddRequestHeaders("User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    pFile->AddRequestHeaders("Host: www.eyou.com");
    pFile->AddRequestHeaders("Content-Length: 78");
    pFile->AddRequestHeaders("Connection: Keep-Alive");
    pFile->AddRequestHeaders("Cache-Control: no-cache");
    pFile->AddRequestHeaders("Cookie: scid=1104977975203713"); pFile->SendRequest(NULL,0,strFormData.GetBuffer(0),strFormData.GetLength());
    DWORD dwStatusCode;
    int ii=0;
    pFile->QueryInfoStatusCode(dwStatusCode);        
        if(dwStatusCode==HTTP_STATUS_OK)
    {
    //CString mStr1;
    mStr="";
    int nRead=1;
    for(;nRead>0;)
    {

    nRead=pFile->Read(pStr,nLength);
    mStr=mStr+LPCSTR(pStr);
    }
    }得到的响应如下:
    HTTP/1.1 405 Method Not Allowed
    Date: Mon, 16 May 2005 08:48:50 GMT
    Server: Apache/1.3.28 (Unix)
    Allow: GET, HEAD, OPTIONS, TRACE
    Keep-Alive: timeout=15, max=100
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: text/html; charset=iso-8859-1