.NET

HttpClient & Networking

HttpClient, HttpClientFactory, request/response, error handling, retry policies, async patterns

20 면접 질문·
Mid-Level
1

Why use IHttpClientFactory instead of instantiating HttpClient directly?

답변

IHttpClientFactory automatically manages the lifecycle of HttpClient instances and prevents socket exhaustion. Directly instantiating HttpClient in a using statement can cause TIME_WAIT connection issues that remain open even after disposal. Using IHttpClientFactory also enables configuring resilience policies with Polly and efficiently managing connection pooling.

2

What is the main difference between a Named Client and a Typed Client?

답변

A Typed Client encapsulates HTTP call logic in a dedicated class with dependency injection, while a Named Client is retrieved via IHttpClientFactory.CreateClient(name). Typed Clients offer better separation of concerns and facilitate unit testing by encapsulating configuration and business logic. Named Clients are useful for simple cases where multiple different configurations are needed without complex business logic.

3

How to configure a global timeout for all HttpClient instances in an application?

답변

Configuring the timeout via ConfigurePrimaryHttpMessageHandler allows defining a timeout at the handler level that will apply to all clients created by the factory. This approach centralizes configuration and avoids code repetition. It's also possible to configure the timeout individually on each HttpClient, but this becomes difficult to maintain in a large application with multiple configured clients.

4

Which method allows reading the body of an HTTP response as a string?

5

What is the role of a DelegatingHandler in the HttpClient pipeline?

+17 면접 질문

다음 면접을 위해 .NET을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기