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;
        } 
    }

    复制代码

    http://www.cnblogs.com/coderzh/archive/2008/11/24/1340134.html

  • 相关阅读:
    防止重复点击
    刷新当前页面的几种方法
    PHP删除数组中空值
    json转化数组
    两个不能同时共存的条件orWhere查询
    SQLSTATE[42000]
    laravel一个页面两个表格分页处理
    Hash::make与Hash::check
    unbind()清除指定元素绑定效果
    二级联动
  • 原文地址:https://www.cnblogs.com/findumars/p/5794176.html
Copyright © 2011-2022 走看看