Skip to content

Latest commit

 

History

History
73 lines (62 loc) · 2.24 KB

README.md

File metadata and controls

73 lines (62 loc) · 2.24 KB

A simple secondary wrapper for WinHttp

This project may not be updated frequently because a better alternative project has been found: https://github.com/libcpr/cpr

image

Import Methods:

  1. cmake + source

    CMakeLists.txt
    include_directories(${PROJECT_SOURCE_DIR}/WinHttp)
    add_executable(${PROJECT_NAME} main.cpp)
    target_link_libraries(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/lib/Winhttp_SimpleAPI.lib)
    main.cpp
    #include <WinhttpAPI.h>
  2. source only (msvc only)

    main.cpp
    #include "..\\WinhttpAPI.h"
    #pragma comment(lib,"..\\Winhttp_SimpleAPI.lib")

Usage:

First step, import namespace
using namespace Winhttp;
Request a website information
HttpRequestT httpRequest;
HttpResponseT httpResponse;
httpRequest.url = "https://www.baidu.com";
httpRequest.protocol = "get";

WinhttpAPI httpAPI;
httpAPI.SetHeader("Connection","keep-alive");
httpAPI.SetHeader("Context-Type","text/html");
httpAPI.Request(httpRequest,httpResponse);

//Get the content and headers returned from a web visit.
std::cout << "[+]" << httpResponse.body << ", " << httpResponse.headers << '\n';
//Retrieve a specific key value from the returned headers
std::cout << "[+]" << httpAPI.GetHeader("Date") << '\n';
Download a file
HttpRequestT httpRequest = {"https://example.com/1GB.bin", "get", {HttpRequestT::SaveMethodT::FILE_STREAM, "C:\\test.bin"}};
HttpResponseT httpResponse;

WinhttpAPI httpAPI(httpRequest,httpResponse);
httpAPI.request();
//At the same time,the headers exist and the body has empty
Other
  • use encode/decode function
    // transform string to wstring
    std::wstring wStr = CodeCvt::StrToWstr("hello world", CP_ACP);
    
    // transform wstring to string
    std::string str = CodeCvt::WstrToStr(L"hello world", CP_ACP);

Todo

  • Change code style, design mode
  • multithreading support

Thanks:

Licenses for Open Source Development