Network API Reference
This section provides detailed documentation for the networking libraries available in the Microsoft Development Kit. Use the examples and tables below to integrate network functionality into your applications.
Contents
HttpClient Class
The HttpClient
class provides a flexible, high‑level API for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.
Properties
Name | Type | Description |
---|---|---|
BaseAddress | Uri | Base address of the HTTP client. |
Timeout | TimeSpan | Timespan to wait before the request times out. |
DefaultRequestHeaders | HttpHeaders | Headers sent with each request. |
Methods
public Task<HttpResponseMessage> GetAsync(string requestUri);
public Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content);
public void CancelPendingRequests();
WebSocket Client
Provides a real‑time, full‑duplex communication channel over a single TCP connection.
Usage
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
var client = new ClientWebSocket();
await client.ConnectAsync(new Uri("wss://example.com/socket"), CancellationToken.None);
await client.SendAsync(new ArraySegment<byte>(Encoding.UTF8.GetBytes("Hello")), WebSocketMessageType.Text, true, CancellationToken.None);
var buffer = new byte[1024];
var result = await client.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
Console.WriteLine(Encoding.UTF8.GetString(buffer, 0, result.Count));
await client.CloseAsync(WebSocketCloseStatus.NormalClosure, "Done", CancellationToken.None);
DnsResolver
Static helper class for DNS lookups.
var addresses = await Dns.GetHostAddressesAsync("example.com");
foreach (var ip in addresses)
{
Console.WriteLine(ip);
}
Complete Sample
Download the network-sample.zip archive containing a Visual Studio solution that demonstrates HTTP, WebSocket, and DNS usage.