本帖最后由 jacktion2004 于 2010-08-12 20:04:19 编辑

解决方案 »

  1.   

    有没有处理丢包的问题?HTTP协议不太清楚,TCP/IP自行处理丢包判断,UDP没有这个功能。
      

  2.   

    问题应该出在CString类, 程序在VC6没有问题,因为CString在VC6下是处理单字节字符的,而在VS2008下处理的是unicode,所在才会出问题, 而且不管是CString还是char都只是处理字符串的,而你接收的数据是二进制的,不出问题才怪呢。改一个程序吧CString            strSend,strHeader,strRange;
        
        int                iStatus = 0,nRet;
        int      readbuflen  = 1024;
        void            szReadBuf;
        DWORD            dwContentLength,dwStatusCode;
        
        while (TRUE)
        {
            if(m_pSocket.m_hSocket != NULL)
                m_pSocket.Close();
            m_pSocket.Create();
            m_pSocket.Connect(m_strServer, m_nPort);
            
            strSend  = strVerb  + m_strObject + " HTTP/1.1\r\n";
            strSend += "Host: " + m_strServer + "\r\n";
            strSend += "Accept: */*\r\n";
            strSend += "Pragma: no-cache\r\n"; 
            strSend += "Cache-Control: no-cache\r\n";
            if( !m_strReferer.IsEmpty() )
                strSend += "Referer: " + m_strReferer + "\r\n";
            strSend += "Connection: close\r\n";
            strRange = "Range: bytes=100-\r\n";
            strSend += strRange;
            //必须要加一个空行,否则Http服务器将不会应答
            strSend += "\r\n";
            
            int ret = m_pSocket.Send(strSend.GetBuffer(0), strSend.GetLength());
            strSend.ReleaseBuffer();
            
            szReadBuf = malloc(readbuflen);
            if(szReadBuf == NULL) break;
            ZeroMemory(szReadBuf,1024);
            while(readbuflen > 0)  //最大接收1024
            {
                ret = m_pSocket.Receive((char *)szReadBuf + (1024 - readbuflen), readbuflen);
                
                if( szReadBuf[0] == '\0' ) // We have encountered "\r\n\r\n"
                    break;             
                readbuflen -= ret;            if( iStatus == 0)
                    strHeader += "\r\n";
            }
            
            nRet = GetInfo(strHeader,dwContentLength,
                dwStatusCode,m_TimeLastModified);/////////这一句做相应的修改
      

  3.   

    http 构造报文肯定有问题
     不然你收到的数据肯定是正确的
    期待接分
      

  4.   

    抓包看你发送的HTTP请求是不是正确的
      

  5.   

    Content-Type: application/zip人家已经告诉你是zip压缩过的数据了 当然是乱码啦
    接完要用zlib解压一下
      

  6.   

    压缩后的文件有进行过AES加密你看到的当然是乱码
    貌似VC6对乱码不解释