前段时间在使用poco,进行http的连接,封包,发包,拆包发包时可以设置COOKIE,可以添加附加数据
收包时可以自动得到HTTP头,得到不同的字段,然后还可以得到COOKIE,可以自动完全的结束收包的过程感觉上很实用,但是这个是用VS 2003,VS2005这些编译的,在VC6上使用会有些问题,不知道哪位还知道有没有开源的,封装好了的,类似功能的开源代码,小弟万分感谢!!!

解决方案 »

  1.   

    我有呢
    UINT CRequest::Request(TSubmitInfo *pSi)
    {
    CString strObject;
    INTERNET_PORT nPort;
    CString strServer;
    CString strHeaders =_T("Content-Type: application/x-www-form-urlencoded");     CString strFormData;
    CString strURL;
    int (*funCall)(CWnd * ,CString,BOOL ); BOOL bPost;
        DWORD dwServiceType;
    CString strContent="";
    CHttpConnection* pServer = NULL;
    CHttpFile* pFile = NULL;
    CInternetSession  *pSession;
    CWnd *pWnd;// TSubmitInfo *pSi=(TSubmitInfo *)lParam; strURL=pSi->url; //请求的URL地址
    strFormData=pSi->strPostData;//要发送的POST数据,如果是Send那么可为空
    funCall=pSi->funCall; //回调函数,功能失败都用调用,有三个参数分别为窗口句柄,网页返回内容,是否成功 
    bPost=pSi->bPost;//是否为POST方式
    pSession=pSi->pSession; //Session
    pWnd=pSi->pWnd;  //调用窗口句柄
    // delete pSi;

    try
    {
    if(!AfxParseURL(strURL,dwServiceType,strServer,strObject,nPort)||
    dwServiceType != INTERNET_SERVICE_HTTP)
    {
    //MessageBox(_T("²»ÊÇHTTPÕ¾µã"),_T("´íÎó"));
    return 0;
    }
    pServer = pSession->GetHttpConnection(strServer,nPort); if( bPost )
    pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strObject);//NULL,1,NULL,NULL,
    else
    pFile = pServer->OpenRequest(1,strObject,NULL,1,NULL,NULL,
                                         INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_DONT_CACHE );
    pFile->AddRequestHeaders(_T("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(_T("Referer: ")+strURL);
    pFile->AddRequestHeaders(_T("Accept-Language: zh-cn"));
    pFile->AddRequestHeaders(_T("Content-Type: application/x-www-form-urlencoded"));
    pFile->AddRequestHeaders(_T("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)")); BOOL result;
    if( bPost )
    result = pFile->SendRequest(NULL,0, 
     (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength()); 
    else
    result = pFile->SendRequest();
    DWORD dwRet;
    pFile->QueryInfoStatusCode(dwRet); if (dwRet != HTTP_STATUS_OK)
    {
    //MessageBox("¶ÁÈ¡µÇ¼ʱ״̬²»ÕýÈ·!\n");
    if( funCall )
    (*funCall)(pWnd,"",FALSE);
    return 0;
    }
    //如果有cookie ,设置
    CString cookie;
    pFile->QueryInfo(HTTP_QUERY_SET_COOKIE,cookie);
    if( cookie!="" )
    pSession->SetCookie(strURL,"",cookie);


    CString strLine,strContent;
    BOOL bGood;
    //读取返回内容 
    while(1)
    {
    bGood=pFile->ReadString(strLine);
    strContent+=strLine+"\n";
    if( !bGood )break;

    }

    CString contenttype,strGb;
    pFile->QueryInfo(HTTP_QUERY_CONTENT_TYPE,contenttype);
    //如果是utf-8编码,要转换,不然中文都是乱码了
                     if( contenttype.Find("utf-8")!=-1 )
    {

    CChineseCodeLib::UTF_8ToGB2312(strGb,(char *)(LPCTSTR)strContent,strContent.GetLength());
    strContent=strGb;
    }
                    //有回调函数,执行回调函数
    if( funCall )
    (*funCall)(pWnd,strContent,TRUE);
    pFile->Close();
    pServer->Close();
    if (pFile != NULL)
    delete pFile;
    if (pServer != NULL)
    delete pServer;
    }
    catch (CInternetException* pEx)
    {
    char szErr[256];
    if(!pEx->GetErrorMessage(szErr, 256)) 
              strcpy(szErr,"Some crazy unknown error"); 

            pFile->Close();
    delete pFile;
            pServer->Close(); 
            delete pServer; 
            pEx->Delete(); 
    //失败就返回FALSE
    if( funCall )
    (*funCall)(pWnd,"",FALSE);

            return 0; 
    }
    return 1;
    }
      

  2.   

    - -!您这个代码给我也没有办法用啊
    最好是sourceforge.net上有的,我可以直接去下载的不知道哪位大哥知道!!