A Windows HTTP client for package:http using the
native WinHTTP API.
Using WinHTTP, rather than the socket-based
dart:io HttpClient implementation, has several
advantages:
- It automatically supports Windows system proxy settings (WPAD, PAC scripts).
- It uses the Windows TLS stack (Schannel) with system certificate stores.
- It supports automatic gzip/deflate decompression.
- It integrates with Windows network diagnostics and logging.
- Windows 8.1 or later (required for automatic proxy detection and decompression)
- Dart SDK 3.4+
The easiest way to use this library is via the high-level interface
defined by package:http Client.
This approach allows the same HTTP code to be used on all platforms, while still allowing platform-specific setup.
import 'dart:io';
import 'package:http/http.dart';
import 'package:http/io_client.dart';
import 'package:win_http/win_http.dart';
void main() async {
final Client httpClient;
if (Platform.isWindows) {
httpClient = WinHttpClient.defaultConfiguration();
} else {
httpClient = IOClient();
}
final response = await httpClient.get(
Uri.https('www.googleapis.com', '/books/v1/volumes', {'q': 'dart'}),
);
print('Status: ${response.statusCode}');
httpClient.close();
}Use WinHttpClient.fromConfiguration for custom settings:
final client = WinHttpClient.fromConfiguration(
WinHttpClientConfiguration(
userAgent: 'MyApp/1.0',
connectTimeout: Duration(seconds: 10),
receiveTimeout: Duration(seconds: 30),
),
);By default, WinHttpClient uses automatic proxy detection
(WinHttpAccessType.automatic). You can configure a named proxy:
final client = WinHttpClient.fromConfiguration(
WinHttpClientConfiguration(
accessType: WinHttpAccessType.named,
proxy: 'proxy.example.com:8080',
proxyBypass: 'localhost;*.local',
),
);Or disable the proxy entirely:
final client = WinHttpClient.fromConfiguration(
WinHttpClientConfiguration(
accessType: WinHttpAccessType.noProxy,
),
);| Feature | Status |
|---|---|
| HTTP/HTTPS | Supported |
| GET, POST, PUT, PATCH, DELETE, HEAD | Supported |
| Request headers | Supported |
| Response streaming | Supported |
| Redirect following | Supported (configurable) |
| Gzip/deflate decompression | Automatic |
| System proxy (WPAD/PAC) | Automatic |
| TLS via Windows Schannel | Automatic |
| Cookies | Per-request only (no cross-request cookie jar) |
| Abort/cancel | Partial (response-stream abort works; pre-send abort requires async WinHTTP) |
| Streaming request body | Not supported (body materialized in memory) |
-
Request bodies are buffered in memory. The entire request body is materialized before sending, similar to
cronet_http. This is fine for typical API payloads but not ideal for multi-GB uploads. -
Headers persist across redirects. WinHTTP transfers request headers (including
Authorization) across redirect hops. Be cautious with sensitive headers when following redirects to untrusted domains. -
Folded headers. WinHTTP handles RFC 2822 folded headers internally but normalizes whitespace differently than some clients expect.