Getting started

edit

Install the package

Add the Meziantou.Framework.HttpArchive package to a project:

dotnet package add Meziantou.Framework.HttpArchive

The examples of this documentation omit the using directives: they need using Meziantou.Framework.HttpArchive;.

Read a HAR file

HarDocument.ParseAsync reads an archive from a stream, such as a file exported from a browser:

await using var stream = File.OpenRead("traffic.har");
var document = await HarDocument.ParseAsync(stream);

foreach (var entry in document.Log?.Entries ?? [])
{
    Console.WriteLine($"{entry.Request?.Method} {entry.Request?.Url} -> {entry.Response?.Status}");
}

document.Log.Entries lists the requests in the order the archive stores them. The ?. and ?? [] are there because the model is nullable: an archive can hold null for any field. See Missing and null values.

Read the entries

HarDocument.Parse reads an archive from a string. Each entry has the Request, the Response, and the time it took in milliseconds:

var document = HarDocument.Parse("""
    {
      "log": {
        "version": "1.2",
        "creator": { "name": "MyTool", "version": "1.0" },
        "entries": [
          {
            "startedDateTime": "2026-01-15T10:00:00.000Z",
            "time": 42.5,
            "request": { "method": "GET", "url": "https://example.com/api/items" },
            "response": { "status": 200, "statusText": "OK", "content": { "size": 2, "mimeType": "application/json", "text": "[]" } }
          }
        ]
      }
    }
    """);

var entry = Assert.Single(document.Log!.Entries!);
Assert.Equal("GET", entry.Request!.Method);
Assert.Equal("https://example.com/api/items", entry.Request.Url);
Assert.Equal(200, entry.Response!.Status);
Assert.Equal("[]", entry.Response.Content!.Text);
Assert.Equal(42.5, entry.Time);

The response body is in Response.Content.Text. A binary body is stored as base64: see Get the bytes of a body.

Next steps