HTTP API Reference

This section provides detailed reference information for the Windows HTTP APIs, enabling developers to build powerful and efficient network-enabled applications.

Core HTTP Functions

These functions form the foundation of HTTP communication on Windows. They allow for the creation of HTTP sessions, requests, and responses.

HttpOpenRequest

Opens an HTTP request handle. This handle is used to specify the details of an HTTP request before sending it to the server.

Parameters

Return Value

Returns a handle to the HTTP request if successful, otherwise NULL.

HttpSendRequest

Sends the specified HTTP request to the server specified by the hConnect parameter.

Parameters

Return Value

Returns TRUE if the request is sent successfully, FALSE otherwise.

HttpQueryResponseHeaders

Retrieves the headers from an HTTP server response.

Parameters

Return Value

Returns TRUE if headers are retrieved successfully, FALSE otherwise.

HTTP Session Management

Manage the lifecycle of HTTP sessions and connections.

HttpConnect

Establishes a connection to an HTTP server.

Parameters

Return Value

Returns a handle to the HTTP connection if successful, otherwise NULL.

Advanced Features

Explore more advanced functionalities like handling authentication and managing cookies.

HttpSetOption

Sets HTTP-specific options for an Internet handle.

Parameters

Return Value

Returns TRUE on success, FALSE on failure.

Note: This documentation is a high-level overview. For complete details on parameters, return values, and error handling, please refer to the official Windows SDK documentation.

// Example Snippet: Sending a simple GET request
HINTERNET hSession = InternetOpen(L"MyApp", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!hSession) { /* Handle error */ }

HINTERNET hConnect = HttpConnect(hSession, L"www.example.com", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, 0, 0, NULL);
if (!hConnect) { /* Handle error */ }

HINTERNET hRequest = HttpOpenRequest(hConnect, L"GET", L"/index.html", NULL, NULL, NULL, 0, 0);
if (!hRequest) { /* Handle error */ }

if (!HttpSendRequest(hRequest, NULL, 0, NULL, 0)) { /* Handle error */ }

// ... process response ...

InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);