HTTP/1.0 200 OK
Date: Tue, 22 Mar 2005 05:39:19 GMT
Server: Apache/2.0.52 (Unix)
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Cache-Control: max-age=300
Expires: Tue, 22 Mar 2005 05:44:19 GMT
Content-Length: 25087
Content-Type: text/html; charset=zh_CN.GB2312
Age: 76
X-Cache: HIT from cachea.china.com
Connection: keep-alive?(57骨蘓?.&謓K?驸薿闠謩?羂倷??V?羶皕E试裚€竊???澵殩笝]v}?鼉訧ю鉃嶝豦?S訇#f逳廉鶜>嵛*fQ惁
7盀=援扲凵
?垌u?艀譮銈幊;3軛&軇щ0<y儳3艹+%1@経铍S2這睏犒撛釤脱u?h3軇⒃(A潄€?縀
???b桀?曝ju:峃 想噌?嘒.??Rz鞓(q蹷?狒殸誰? ?穓螨?Pk??g牛/D ?線凲帨皨iEf??啨??A(擫0F?樧?篮傀醑绠婫c?)屃泋憨X$??嵤呹芤鶱癍唿?耦飤+绷K闔镃?l刼p礰?櫺^z憼@穆唩?嶻hwpX?p膻&ge(
蚌陰#/璋?Z痔骹7za4y]澍?n0#?2P灂衼澙?+F窰菭
?仾?;辪Y K戝噮sN?蓮s鱺!o)t`+纫??c) `?縈 e鼹?yk?{A朏綈Fk? 茽3玱?涩-G耴蝣B??!??Ie?[攮-售 <]蚄Q郛諙缬'瓰E匍2雿F>;J?閙OW/'婵?璬壟鸻j
*L?V&挒鹦悆^F忱谐A??Bub饎&FmOY7褘摼|煽?21鮸フ磿鑱]Nm翸|&?貅8;??!>7姏绂鸂擣N濡&}渂虼?on*?几kLcwj∟飪sN{

解决方案 »

  1.   

    sock.Create();
    sock.Connect(m_url,80);
    CString str;
    str="GET / HTTP/1.1\r\n";
    str+="Accept: image/gif, */*\r\n";
        str+="Accept-Language: zh-cn\r\n";
    str+="Accept-Encoding: gzip,deflate\r\n";
        str+="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)\r\n";
        str+="Host:";
    str+=m_url;
    str+="\r\n";
    str+="Connection: Keep-Alive\r\n\r\n";
    sock.Send(str,str.GetLength(),0);m_post=str;
    CFile fp;
    fp.Open("c:\\test.htm",CFile::modeCreate|CFile::modeWrite);
    DWORD len=0;
    char buf[4096];
    memset(buf,0,4096);
    len=sock.Receive(buf,4096);
    LPSTR head=new char[1024]; memset(head,0,1024);
    sscanf(buf,"%[^<]html",head);
    m_response=head;
    fp.Write(buf,len);
    CString html;
    CString text;
    html.Format("%s",buf);
    while(len != 0)
    {
    text+=html;
    memset(buf,0,4096);
    len=sock.Receive(buf,4096);
    html.Format("%s",buf);
    fp.Write(buf,len);
    }
    char*p=strstr(text,"<html>");

    m_rich.SetWindowText(p);
    UpdateData(FALSE);
    sock.Close();
    fp.Close();
      

  2.   

    1、仔细检查str格式是否正确
    2、最好改为
    CString html = "";
    CString text = "";
    3、程序流程没发现问题,但这个程序有些不安全:错误没有判断,异常没有处理
      

  3.   

    如果你只是想取一个html的源码,完全可以使用CInternetSession::OpenURL()来完成。把它的返回值CStdioFile指针,写入到一个文件里,就可以了。
      

  4.   

    你可以换个URL试试,如果仍就乱码,说明你程序有问题,否则,URL有问题
      

  5.   

    我发现是压缩的原因---》gzip如何处理呀???
      

  6.   

    使用CInternetSession::OpenURL()来下载
    http://news.sina.com.cn/c/2005-03-24/02575445409s.shtml网页
    还是出现怪吗!!!
      

  7.   

    我的代码是。。
    CInternetSession session;
    CInternetFile *file=NULL;
    try
    {
    file = (CInternetFile*) session.OpenURL(m_url); 
    }
    catch (CInternetException* m_pException)
    {
    file = NULL; 
    m_pException->Delete();
    return;
    }
    CStdioFile dataStore;
    if (file)
    {
    CString  somecode;
    BOOL bIsOk = dataStore.Open("d:\\default.htm",
    CFile::modeCreate 
    | CFile::modeWrite 
    | CFile::shareDenyWrite 
    | CFile::typeText);

    if (!bIsOk)
    return;
    while (file->ReadString(somecode) != NULL) 
                      {
    m_text+=somecode;
    m_text+="\n";
    dataStore.WriteString(somecode);
    dataStore.WriteString("\n");
                      }
    file->Close();
    delete file;
    UpdateData(FALSE);
    }
    else
    {
    MessageBox(_T("到指定服务器的连接建立失败..."));
    }