Understanding Kerberos in IronPDF

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

Kerberos認証でUrlToPdfを動作させるにはどうすればいいですか?

IronPDFのUrlToPdfでKerberos認証を使用するためには、レンダリング設定でユーザー名とパスワードを設定する必要があります。 詳細についてはIronPDFのドキュメントを参照してください: IronPdf.ChromeHttpLoginCredentials

HTMLコンテンツをダウンロードするには、後でレンダリングできるSystem.Net.Http.HttpClientの使用をお勧めします。 このアプローチを使用すると、IronPDFがコンテンツを処理する前に、認証が必要なものを含むHTTPリクエストを処理できます。

Kerberosを使用してページをダウンロードするためのオンラインガイドはこちらです: How does the System.Net.Http.HttpClient select authentication type?。 このStackOverflowリンクは、HttpClientを使用した認証の実装に関する詳細な議論を提供します。

HTML内のすべての必要なアセットがダウンロードされていることを確認するには、HTML Agility Packの使用を検討してください。 この.NETライブラリは、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

重要なポイント:

  • HttpClient と HttpClientHandler: 現在のユーザーの資格情報を使用してKerberos認証を許可するためにHttpClientHandlerUseDefaultCredentials = trueで使用します。
  • エラーハンドリング: HTTPリクエスト中の例外を管理するためにtry-catchブロックを実装します。
  • HTMLレンダリング: HTMLがフェッチされたら、必要に応じてIronPDFを使用してコンテンツをPDFにレンダリングします。
Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はいいですか?
Nuget ダウンロード 16,154,058 | バージョン: 2025.11 ただ今リリースされました