zoukankan      html  css  js  c++  java
  • 使用CInternetSession和CHttpFile读取网页内容

    参考网址:http://www.398588.com/Article/T9/78.aspx
    读取网页的内容可以类比本地的文件一下,代码如下:
    #include   <afxinet.h>

    CString url;
        GetDlgItemText(IDC_EDIT1,url);
        CInternetSession Sess;
        CHttpFile
    * cFile = (CHttpFile*)Sess.OpenURL(url,1,INTERNET_FLAG_TRANSFER_ASCII||INTERNET_FLAG_RELOAD,NULL,0);
        
        DWORD dwStatusCode;
        cFile
    ->QueryInfoStatusCode(dwStatusCode);
        
    if(dwStatusCode == HTTP_STATUS_OK)
        
    {
            CString szData,szAllData;
            
    while(cFile->ReadString(szData))
            
    {
                szAllData 
    += szData;
                szAllData 
    += "\r\n";
            }

            
            cFile
    ->Close();
            Sess.Close();
            CString name 
    ;
            name 
    = "sd.htm";
            CFile file(name, CFile::modeCreate 
    | CFile::modeWrite);
            file.Write(szAllData,szAllData.GetLength());
            file.Close();
        }

        
    else
        
    {
            MessageBox(
    "请求失败。。。。");
        }


    用CInternetSession打开url得到一个CHttpFile,用ReadString读取CHttpFile中的内容。

  • 相关阅读:
    Docker学习总结(四)--应用部署
    strcat的由来
    ubuntu man不到pthread_mutex_XX
    string::front
    string::find_last_of
    string::find_last_not_of
    string::find_first_of
    string::find_first_not_of
    string::erase
    string::empty
  • 原文地址:https://www.cnblogs.com/zhwl/p/2783319.html
Copyright © 2011-2022 走看看