Understanding Kerberos in IronPDF

This article was translated from English: Does it need improvement?
Translated
View the article in English

Comment faire fonctionner UrlToPdf avec l'authentification Kerberos ?

Pour utiliser l'authentification Kerberos avec UrlToPdf d'IronPDF, vous devez définir un nom d'utilisateur et un mot de passe dans les paramètres de rendu. Vous pouvez consulter la documentation d'IronPDF pour plus de détails : IronPdf.ChromeHttpLoginCredentials.

Nous recommandons d'utiliser System.Net.Http.HttpClient pour télécharger le contenu HTML, que vous pouvez ensuite rendre. Cette approche vous permet de gérer les requêtes HTTP, y compris celles nécessitant une authentification, avant qu'IronPDF ne traite le contenu.

Voici un guide en ligne sur le téléchargement de pages avec Kerberos : Comment le System.Net.Http.HttpClient choisit-il le type d'authentification ?. Ce lien StackOverflow fournit une discussion détaillée sur la mise en œuvre de l'authentification à l'aide de HttpClient.

Pour analyser et assurer que tous les éléments nécessaires au sein du HTML sont téléchargés, envisagez d'utiliser le HTML Agility Pack. Cette librairie .NET aide à manipuler et interroger efficacement les documents HTML.

// Example: Using HttpClient with Kerberos Authentication

// Import the necessary namespaces
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace KerberosAuthenticationExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Create an instance of HttpClient
            HttpClientHandler handler = new HttpClientHandler
            {
                // Automatically use default network credentials
                UseDefaultCredentials = true // Enables Windows authentication (e.g., Kerberos)
            };

            using HttpClient httpClient = new HttpClient(handler);

            try
            {
                // Send a GET request to the desired URL
                HttpResponseMessage response = await httpClient.GetAsync("https://your-secure-url.com");

                // Ensure the request was successful
                response.EnsureSuccessStatusCode();

                // Read and display the response body
                string responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseBody);

                // If needed, render the HTML to PDF with IronPDF here
                // IronPdf.HtmlToPdf renderer = new IronPdf.HtmlToPdf();
                // renderer.RenderHtmlAsPdf(responseBody).SaveAs("output.pdf");
            }
            catch (HttpRequestException e)
            {
                // Handle any error responses from the server or connection issues
                Console.WriteLine("\nException Caught!");
                Console.WriteLine($"Message :{e.Message}");
            }
        }
    }
}
// Example: Using HttpClient with Kerberos Authentication

// Import the necessary namespaces
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace KerberosAuthenticationExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Create an instance of HttpClient
            HttpClientHandler handler = new HttpClientHandler
            {
                // Automatically use default network credentials
                UseDefaultCredentials = true // Enables Windows authentication (e.g., Kerberos)
            };

            using HttpClient httpClient = new HttpClient(handler);

            try
            {
                // Send a GET request to the desired URL
                HttpResponseMessage response = await httpClient.GetAsync("https://your-secure-url.com");

                // Ensure the request was successful
                response.EnsureSuccessStatusCode();

                // Read and display the response body
                string responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseBody);

                // If needed, render the HTML to PDF with IronPDF here
                // IronPdf.HtmlToPdf renderer = new IronPdf.HtmlToPdf();
                // renderer.RenderHtmlAsPdf(responseBody).SaveAs("output.pdf");
            }
            catch (HttpRequestException e)
            {
                // Handle any error responses from the server or connection issues
                Console.WriteLine("\nException Caught!");
                Console.WriteLine($"Message :{e.Message}");
            }
        }
    }
}
' Example: Using HttpClient with Kerberos Authentication

' Import the necessary namespaces
Imports Microsoft.VisualBasic
Imports System
Imports System.Net
Imports System.Net.Http
Imports System.Net.Http.Headers
Imports System.Threading.Tasks

Namespace KerberosAuthenticationExample
	Friend Class Program
		Shared Async Function Main(ByVal args() As String) As Task
			' Create an instance of HttpClient
			Dim handler As New HttpClientHandler With {.UseDefaultCredentials = True}

			Using httpClient As New HttpClient(handler)
	
				Try
					' Send a GET request to the desired URL
					Dim response As HttpResponseMessage = Await httpClient.GetAsync("https://your-secure-url.com")
	
					' Ensure the request was successful
					response.EnsureSuccessStatusCode()
	
					' Read and display the response body
					Dim responseBody As String = Await response.Content.ReadAsStringAsync()
					Console.WriteLine(responseBody)
	
					' If needed, render the HTML to PDF with IronPDF here
					' IronPdf.HtmlToPdf renderer = new IronPdf.HtmlToPdf();
					' renderer.RenderHtmlAsPdf(responseBody).SaveAs("output.pdf");
				Catch e As HttpRequestException
					' Handle any error responses from the server or connection issues
					Console.WriteLine(vbLf & "Exception Caught!")
					Console.WriteLine($"Message :{e.Message}")
				End Try
			End Using
		End Function
	End Class
End Namespace
$vbLabelText   $csharpLabel

Points clés :

  • HttpClient et HttpClientHandler : Utilisez HttpClientHandler avec UseDefaultCredentials = true pour permettre l'authentification Kerberos en utilisant les identifiants de l'utilisateur actuel.
  • Gestion des erreurs : Implémentez des blocs try-catch pour gérer les exceptions lors des requêtes HTTP.
  • Rendu HTML : Une fois le HTML récupéré, utilisez IronPDF pour rendre le contenu en PDF si nécessaire.
Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Nuget Téléchargements 16,154,058 | Version : 2025.11 vient de sortir