# .NET (/fr/quickstarts/dotnet)

<!-- agent-signals: reading_time_min: 5 · est_tokens: 2648 · updated: 2026-07-30 -->
Related: [Node.js](/fr/quickstarts/nodejs.md), [Next.js](/fr/quickstarts/nextjs.md), [Express](/fr/quickstarts/express.md), [NestJS](/fr/quickstarts/nestjs.md), [Fastify](/fr/quickstarts/fastify.md), [Hono](/fr/quickstarts/hono.md)

<div id="prerequisites">
  ## Prérequis [#prérequis]
</div>

* .NET 6.0+
* Une clé API Firecrawl — [obtenez-en une gratuitement](https://www.firecrawl.dev/app/api-keys)

<div id="search-the-web">
  ## Recherche sur le web [#recherche-sur-le-web]
</div>

Firecrawl prend en charge .NET via l’API REST avec `HttpClient`.

```csharp
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

var apiKey = Environment.GetEnvironmentVariable("FIRECRAWL_API_KEY");
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

var content = new StringContent(
    JsonSerializer.Serialize(new { query = "firecrawl web scraping", limit = 5 }),
    Encoding.UTF8,
    "application/json"
);

var response = await client.PostAsync("https://api.firecrawl.dev/v2/search", content);
var json = await response.Content.ReadAsStringAsync();
Console.WriteLine(json);
```

<Accordion title="Exemple de réponse">
  ```json
  {
    "success": true,
    "data": {
      "web": [
        {
          "url": "https://docs.firecrawl.dev",
          "title": "Firecrawl Documentation",
          "markdown": "# Firecrawl\n\nFirecrawl is a web scraping API..."
        }
      ]
    }
  }
  ```
</Accordion>

<div id="scrape-a-page">
  ## Scraper une page [#scraper-une-page]
</div>

```csharp
var scrapeContent = new StringContent(
    JsonSerializer.Serialize(new { url = "https://example.com" }),
    Encoding.UTF8,
    "application/json"
);

var scrapeResponse = await client.PostAsync("https://api.firecrawl.dev/v2/scrape", scrapeContent);
var scrapeJson = await scrapeResponse.Content.ReadAsStringAsync();

using var doc = JsonDocument.Parse(scrapeJson);
var markdown = doc.RootElement.GetProperty("data").GetProperty("markdown").GetString();
Console.WriteLine(markdown);
```

<Accordion title="Exemple de réponse">
  ```json
  {
    "success": true,
    "data": {
      "markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
      "metadata": {
        "title": "Example Domain",
        "sourceURL": "https://example.com"
      }
    }
  }
  ```
</Accordion>

<div id="interact-with-a-page">
  ## Interact avec une page [#interact-avec-une-page]
</div>

Démarrez une session de navigateur, interagissez avec la page à l’aide d’instructions en langage naturel, puis fermez la session.

<div id="step-1-scrape-to-start-a-session">
  ### Étape 1 — Scrapez pour démarrer une session [#étape-1--scrapez-pour-démarrer-une-session]
</div>

```csharp
var sessionContent = new StringContent(
    JsonSerializer.Serialize(new { url = "https://www.amazon.com", formats = new[] { "markdown" } }),
    Encoding.UTF8,
    "application/json"
);

var sessionResponse = await client.PostAsync("https://api.firecrawl.dev/v2/scrape", sessionContent);
var sessionJson = await sessionResponse.Content.ReadAsStringAsync();

using var sessionDoc = JsonDocument.Parse(sessionJson);
var scrapeId = sessionDoc.RootElement
    .GetProperty("data")
    .GetProperty("metadata")
    .GetProperty("scrapeId")
    .GetString();

Console.WriteLine($"scrapeId: {scrapeId}");
```

<div id="step-2-send-interactions">
  ### Étape 2 — Envoyer les interactions [#étape-2--envoyer-les-interactions]
</div>

```csharp
var interactUrl = $"https://api.firecrawl.dev/v2/scrape/{scrapeId}/interact";

// Rechercher un produit
var searchBody = new StringContent(
    JsonSerializer.Serialize(new { prompt = "Search for iPhone 16 Pro Max" }),
    Encoding.UTF8,
    "application/json"
);

var searchResult = await client.PostAsync(interactUrl, searchBody);
Console.WriteLine(await searchResult.Content.ReadAsStringAsync());

// Cliquer sur le premier résultat
var clickBody = new StringContent(
    JsonSerializer.Serialize(new { prompt = "Click on the first result and tell me the price" }),
    Encoding.UTF8,
    "application/json"
);

var clickResult = await client.PostAsync(interactUrl, clickBody);
Console.WriteLine(await clickResult.Content.ReadAsStringAsync());
```

<div id="step-3-stop-the-session">
  ### Étape 3 — Arrêter la session [#étape-3--arrêter-la-session]
</div>

```csharp
await client.DeleteAsync(interactUrl);
Console.WriteLine("Session arrêtée");
```

<div id="reusable-client-class">
  ## Classe de client réutilisable [#classe-de-client-réutilisable]
</div>

Pour une utilisation répétée, encapsulez l’API dans un client typé :

```csharp
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

public class FirecrawlClient
{
    private readonly HttpClient _http;
    private const string BaseUrl = "https://api.firecrawl.dev/v2";

    public FirecrawlClient(string apiKey)
    {
        _http = new HttpClient();
        _http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
    }

    private async Task<JsonDocument> PostAsync(string endpoint, object payload)
    {
        var content = new StringContent(
            JsonSerializer.Serialize(payload),
            Encoding.UTF8,
            "application/json"
        );

        var response = await _http.PostAsync($"{BaseUrl}{endpoint}", content);
        response.EnsureSuccessStatusCode();

        var json = await response.Content.ReadAsStringAsync();
        return JsonDocument.Parse(json);
    }

    public async Task<JsonDocument> ScrapeAsync(string url)
    {
        return await PostAsync("/scrape", new { url });
    }

    public async Task<JsonDocument> SearchAsync(string query, int limit = 5)
    {
        return await PostAsync("/search", new { query, limit });
    }
}

// Utilisation
var firecrawl = new FirecrawlClient(Environment.GetEnvironmentVariable("FIRECRAWL_API_KEY")!);
var result = await firecrawl.SearchAsync("firecrawl web scraping");
Console.WriteLine(result.RootElement);
```

<div id="next-steps">
  ## Prochaines étapes [#prochaines-étapes]
</div>

<CardGroup cols="2">
  <Card title="Docs recherche" icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M8 7L16 7&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M8 11L12 11&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M13 21.5V21C13 18.1716 13 16.7574 13.8787 15.8787C14.7574 15 16.1716 15 19 15H19.5M20 13.3431V10C20 6.22876 20 4.34315 18.8284 3.17157C17.6569 2 15.7712 2 12 2C8.22877 2 6.34315 2 5.17157 3.17157C4 4.34314 4 6.22876 4 10L4 14.5442C4 17.7892 4 19.4117 4.88607 20.5107C5.06508 20.7327 5.26731 20.9349 5.48933 21.1139C6.58831 22 8.21082 22 11.4558 22C12.1614 22 12.5141 22 12.8372 21.886C12.9044 21.8623 12.9702 21.835 13.0345 21.8043C13.3436 21.6564 13.593 21.407 14.0919 20.9081L18.8284 16.1716C19.4065 15.5935 19.6955 15.3045 19.8478 14.9369C20 14.5694 20 14.1606 20 13.3431Z&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" href="/fr/features/search">
    Effectuez une recherche sur le web et obtenez le contenu complet de la page
  </Card>

  <Card title="Docs Scrape" icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M8 7L16 7&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M8 11L12 11&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M13 21.5V21C13 18.1716 13 16.7574 13.8787 15.8787C14.7574 15 16.1716 15 19 15H19.5M20 13.3431V10C20 6.22876 20 4.34315 18.8284 3.17157C17.6569 2 15.7712 2 12 2C8.22877 2 6.34315 2 5.17157 3.17157C4 4.34314 4 6.22876 4 10L4 14.5442C4 17.7892 4 19.4117 4.88607 20.5107C5.06508 20.7327 5.26731 20.9349 5.48933 21.1139C6.58831 22 8.21082 22 11.4558 22C12.1614 22 12.5141 22 12.8372 21.886C12.9044 21.8623 12.9702 21.835 13.0345 21.8043C13.3436 21.6564 13.593 21.407 14.0919 20.9081L18.8284 16.1716C19.4065 15.5935 19.6955 15.3045 19.8478 14.9369C20 14.5694 20 14.1606 20 13.3431Z&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" href="/fr/features/scrape">
    Toutes les options de scrape, y compris les formats, les actions et les proxys
  </Card>

  <Card title="Docs Interact" icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M8 7L16 7&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M8 11L12 11&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M13 21.5V21C13 18.1716 13 16.7574 13.8787 15.8787C14.7574 15 16.1716 15 19 15H19.5M20 13.3431V10C20 6.22876 20 4.34315 18.8284 3.17157C17.6569 2 15.7712 2 12 2C8.22877 2 6.34315 2 5.17157 3.17157C4 4.34314 4 6.22876 4 10L4 14.5442C4 17.7892 4 19.4117 4.88607 20.5107C5.06508 20.7327 5.26731 20.9349 5.48933 21.1139C6.58831 22 8.21082 22 11.4558 22C12.1614 22 12.5141 22 12.8372 21.886C12.9044 21.8623 12.9702 21.835 13.0345 21.8043C13.3436 21.6564 13.593 21.407 14.0919 20.9081L18.8284 16.1716C19.4065 15.5935 19.6955 15.3045 19.8478 14.9369C20 14.5694 20 14.1606 20 13.3431Z&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" href="/fr/features/interact">
    Cliquez, remplissez des formulaires et extrayez du contenu dynamique
  </Card>

  <Card title="Référence API" icon="<svg xmlns=&#x22;http://www.w3.org/2000/svg&#x22; viewBox=&#x22;0 0 24 24&#x22; fill=&#x22;none&#x22;><path d=&#x22;M16 6.99998L19.0664 9.64296C20.3554 10.7541 21 11.3096 21 12C21 12.6903 20.3555 13.2459 19.0664 14.357L16 17&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/><path d=&#x22;M8 6.99998L4.93365 9.64296C3.64455 10.7541 3 11.3096 3 12C3 12.6903 3.64455 13.2459 4.93365 14.357L8 17&#x22; stroke=&#x22;currentColor&#x22; stroke-linecap=&#x22;round&#x22; stroke-linejoin=&#x22;round&#x22; stroke-width=&#x22;1.5&#x22;/></svg>" href="/fr/api-reference/v2-introduction">
    Documentation complète de l’API REST
  </Card>
</CardGroup>
