Overview
HTTP (Hypertext Transfer Protocol) is the foundation of data communication for the World Wide Web. Windows provides a rich set of APIs to create, send, and receive HTTP requests and responses, both synchronously and asynchronously.
Key Features
- WinHTTP – Low‑level HTTP client for native code.
- WinInet – Higher‑level API focused on internet client functionality.
- Windows.Web.Http – Modern C++/C# API for UWP and WinUI applications.
- Support for TLS/SSL, proxy configuration, and authentication.
Simple WinHTTP Example
#include <windows.h>
#include <winhttp.h>
#pragma comment(lib, "winhttp.lib")
int main() {
HINTERNET hSession = WinHttpOpen(L"Sample/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
HINTERNET hConnect = WinHttpConnect(hSession, L"example.com", INTERNET_DEFAULT_HTTP_PORT, 0);
HINTERNET hRequest = WinHttpOpenRequest(hConnect, L"GET", L"/", NULL,
WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES,
0);
WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0,
WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
WinHttpReceiveResponse(hRequest, NULL);
// Process response...
WinHttpCloseHandle(hRequest);
WinHttpCloseHandle(hConnect);
WinHttpCloseHandle(hSession);
return 0;
}
Asynchronous Pattern
All WinHTTP functions have async variants. Use WinHttpSetOption
with WINHTTP_OPTION_CALLBACK
to receive status notifications.