zoukankan      html  css  js  c++  java
  • winhttp get请求https

    #include <vector>
    #include <winsock2.h>
    #include <Winhttp.h>
    #include <windows.h>
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    #pragma comment(lib, "winhttp")
    int main(int argc, char* argv[])
    {
    
        DWORD dwSize = 0;
        DWORD dwDownloaded = 0;
        LPSTR pszOutBuffer;
        BOOL  bResults = FALSE;
        HINTERNET  hSession = NULL,
            hConnect = NULL,
            hRequest = NULL;
    
        // Use WinHttpOpen to obtain a session handle.
        hSession = WinHttpOpen(L"WinHTTP Example/1.0",
            WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
            WINHTTP_NO_PROXY_NAME,
            WINHTTP_NO_PROXY_BYPASS, 0);
    
        // Specify an HTTP server.
        if (hSession)
            hConnect = WinHttpConnect(hSession, L"www.microsoft.com",
                INTERNET_DEFAULT_HTTPS_PORT, 0);
    
        // Create an HTTP request handle.
        // 这边如果要请求具体某个地址的话 把NULL 改成 XXX地址
        if (hConnect)
            hRequest = WinHttpOpenRequest(hConnect, L"GET", NULL,
                NULL, WINHTTP_NO_REFERER,
                WINHTTP_DEFAULT_ACCEPT_TYPES,
                WINHTTP_FLAG_SECURE);
    
    
        // Send a request.
        if (hRequest)
            bResults = WinHttpSendRequest(hRequest,
                WINHTTP_NO_ADDITIONAL_HEADERS,
                0, WINHTTP_NO_REQUEST_DATA, 0,
                0, 0);
    
    
        // End the request.
        if (bResults)
            bResults = WinHttpReceiveResponse(hRequest, NULL);
    
        // Keep checking for data until there is nothing left.
        if (bResults)
            do
            {
                // Check for available data.
                dwSize = 0;
                if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
                    printf("Error %u in WinHttpQueryDataAvailable.
    ", GetLastError());
    
                // Allocate space for the buffer.
                pszOutBuffer = new char[dwSize + 1];
                if (!pszOutBuffer)
                {
                    printf("Out of memory
    ");
                    dwSize = 0;
                }
                else
                {
                    // Read the Data.
                    ZeroMemory(pszOutBuffer, dwSize + 1);
    
                    if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
                        dwSize, &dwDownloaded))
                        printf("Error %u in WinHttpReadData.
    ", GetLastError());
                    else
                        printf("%s
    ", pszOutBuffer);
    
                    // Free the memory allocated to the buffer.
                    delete[] pszOutBuffer;
                }
    
            } while (dwSize > 0);
    
    
            // Report any errors.
            if (!bResults)
                printf("Error %d has occurred.
    ", GetLastError());
    
            // Close any open handles.
            if (hRequest) WinHttpCloseHandle(hRequest);
            if (hConnect) WinHttpCloseHandle(hConnect);
            if (hSession) WinHttpCloseHandle(hSession);
    
    
    
            system("pause");
            return 0;
    }
  • 相关阅读:
    游标
    js问题杂记
    博客园页面设置
    Natas13 Writeup(文件上传,绕过图片签名检测)
    Natas12 Writeup(文件上传漏洞)
    Natas11 Writeup(常见编码、异或逆推、修改cookie)
    Natas10 Writeup(正则表达式、grep命令)
    Natas9 Writeup(命令注入)
    Natas8 Writeup(常见编码、php函数)
    Natas7 Writeup(任意文件读取漏洞)
  • 原文地址:https://www.cnblogs.com/Galesaur-wcy/p/15099578.html
Copyright © 2011-2022 走看看