zoukankan      html  css  js  c++  java
  • WinINet function(1)

    一.Url相关函数

    1.InternetCreateUrl

    Cracks a URL into its component parts.

    #define URL_STRING_TEST    "http://www.cnblogs.com/Clingingboy/archive/2011/11/20/2256200.html"
    void main()
    {   
        TCHAR szHostName[128];
        TCHAR szUrlPath[256];
        URL_COMPONENTS crackedURL;
        ZeroMemory(&crackedURL, sizeof (URL_COMPONENTS));
        crackedURL.dwStructSize     = sizeof (URL_COMPONENTS);
        crackedURL.lpszHostName     = szHostName;
        crackedURL.dwHostNameLength = sizeof(szHostName);
        crackedURL.lpszUrlPath      = szUrlPath;
        crackedURL.dwUrlPathLength  = sizeof(szUrlPath);
        InternetCrackUrl(URL_STRING_TEST,(DWORD)strlen(URL_STRING_TEST),0,&crackedURL);
    }

    2.InternetCreateUrl

    Creates a URL from its component parts.

    DWORD urlLength;
    InternetCreateUrl(&crackedURL,ICU_ESCAPE,szUrlPath,&urlLength);

    3.InternetCanonicalizeUrl

    Canonicalizes a URL, which includes converting unsafe characters and spaces into escape sequences.

    InternetCanonicalizeUrl("http://www.xxx.com/viewthread.php?action=printable&tid=99     ",szUrlPath,&urlLength,ICU_ENCODE_SPACES_ONLY);

    4.InternetCombineUrl

    Combines a base and relative URL into a single URL.

    InternetCombineUrl("http://www.xxx.com/","2256200.html",szUrlPath,&urlLength,ICU_BROWSER_MODE);

    二.Internet基本应用相关函数

    1.InternetOpen

    Initializes an application's use of the WinINet functions.

    2.InternetOpenUrl

    Opens a resource specified by a complete FTP, Gopher, or HTTP URL.

    3.InternetReadFile

    Reads data from a handle opened by the InternetOpenUrl, FtpOpenFile, GopherOpenFile, or HttpOpenRequest function

    4.InternetCloseHandle

    Closes a single Internet handle.

    应用1:打开因特网上指定的文件

    image

    void Download()
    {
    
        DWORD byteread=0;
        char buffer[100];
        memset(buffer,0,100);
        HINTERNET internetopen;
    
    
        internetopen=InternetOpen("Testing",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
        if (internetopen==NULL)
        { 
            cout<<"Internet open failed!"<<endl;
            return;
        }
        HINTERNET internetopenurl;
        internetopenurl=InternetOpenUrl(internetopen,"http://www.cnblogs.com/Clingingboy/archive/2011/11/20/2256200.html",NULL,0,INTERNET_FLAG_RELOAD,0);  
        if (internetopenurl==NULL)
        { 
            cout<<"Internet open url failed!"<<endl; 
            goto there;
        }
    
        BOOL hwrite;
        DWORD written;
        HANDLE createfile;
        createfile=CreateFile("C://a.html",GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
        if (createfile==INVALID_HANDLE_VALUE)
        {  
            cout<<"Create File failed!"<<endl;
            goto next;
        }
    
        BOOL internetreadfile;
        while(1)
        {
            internetreadfile=InternetReadFile(internetopenurl,buffer,sizeof(buffer),&byteread);
            if(byteread==0)  
                break;
            hwrite=WriteFile(createfile,buffer,sizeof(buffer),&written,NULL);
            if (hwrite==0)
            {
                cout<<"Write to file failed!"<<endl;
                goto here;
            }
        }
    
        cout<<"Finished downloading!"<<endl;
    
    here:
        CloseHandle(createfile);
    next: 
        InternetCloseHandle(internetopenurl);
    there:
        InternetCloseHandle(internetopen);
    
    }

    三.连接检查函数

    1.InternetCheckConnection

    Allows an application to check if a connection to the Internet can be established.

    BOOL result=InternetCheckConnection(URL_STRING_TEST,FLAG_ICC_FORCE_CONNECTION,0);

    2.InternetAttemptConnect

    Attempts to make a connection to the Internet.

    BOOL result=InternetAttemptConnect(0);
  • 相关阅读:
    1105 Spiral Matrix (25分)(蛇形填数)
    1104 Sum of Number Segments (20分)(long double)
    1026 Table Tennis (30分)(模拟)
    1091 Acute Stroke (30分)(bfs,连通块个数统计)
    1095 Cars on Campus (30分)(排序)
    1098 Insertion or Heap Sort (25分)(堆排序和插入排序)
    堆以及堆排序详解
    1089 Insert or Merge (25分)
    1088 Rational Arithmetic (20分)(模拟)
    1086 Tree Traversals Again (25分)(树的重构与遍历)
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/2264882.html
Copyright © 2011-2022 走看看