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 "), url);

                BYTE Temp[MAXSIZE];
                ULONG Number = 1;
                while (Number > 0)
                {
                    InternetReadFile(hHttp, Temp, MAXSIZE - 1, &Number);
                    Temp[Number] = '';
                    printf("%s", Temp);
                }
                InternetCloseHandle(hHttp);
                hHttp = NULL;
            }
            InternetCloseHandle(hSession);
            hSession = NULL;
        } 
    }

  • 相关阅读:
    树四:遍历二叉树
    树三:创建二叉树
    树二:二叉树定义及性质
    树一:定义及存储
    排序七:归并排序
    排序六:快速排序
    排序五:希尔排序
    排序四:冒泡排序
    深入分析Linux内核链表
    179. Largest Number
  • 原文地址:https://www.cnblogs.com/mjgw/p/12437411.html
Copyright © 2011-2022 走看看