zoukankan      html  css  js  c++  java
  • C++实现发送HTTP请求

    #include <stdio.h>
    #include 
    <windows.h>
    #include 
    <wininet.h>

    #define MAXSIZE 1024
    #pragma comment(lib, "Wininet.lib") 

    void urlopen(_TCHAR*);

    int _tmain(int argc, _TCHAR* argv[])
    {
        urlopen(_T(
    "http://coderzh.cnblogs.com"));
        
    return 0;
    }

    void urlopen(_TCHAR* url)
    {
        HINTERNET hSession 
    = InternetOpen(_T("UrlTest"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
        
    if(hSession != NULL)
        {
            HINTERNET hHttp 
    = InternetOpenUrl(hSession, url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);

            
    if (hHttp != NULL)
            {
                wprintf_s(_T(
    "%s\n"), url);

                BYTE Temp[MAXSIZE];
                ULONG Number 
    = 1;
                
    while (Number > 0)
                {
                    InternetReadFile(hHttp, Temp, MAXSIZE 
    - 1&Number);
                    Temp[Number] 
    = '\0';
                    printf(
    "%s", Temp);
                }
                InternetCloseHandle(hHttp);
                hHttp 
    = NULL;
            }
            InternetCloseHandle(hSession);
            hSession 
    = NULL;
        } 
    }
  • 相关阅读:
    1062 Talent and Virtue (25 分)
    1083 List Grades (25 分)
    1149 Dangerous Goods Packaging (25 分)
    1121 Damn Single (25 分)
    1120 Friend Numbers (20 分)
    1084 Broken Keyboard (20 分)
    1092 To Buy or Not to Buy (20 分)
    数组与链表
    二叉树
    时间复杂度与空间复杂度
  • 原文地址:https://www.cnblogs.com/coderzh/p/1340134.html
Copyright © 2011-2022 走看看