Skip to content
Sharp

Networking · interview question

How can you specify a custom timeout for a request using HttpClient?

Multiple choiceMediumchapter-11-curatedpremiumnetworkinghttpclient-basics
java
HttpRequest request = HttpRequest.newBuilder().timeout(Duration.ofSeconds(10)).build();
Choose one answer
Answer and explanation

Correct answer

B. By using the timeout() method on HttpRequest.Builder

Why

The timeout() method on HttpRequest.Builder allows you to specify a timeout for each individual request, ensuring that the request doesn't hang indefinitely if the server is unresponsive.

Test yourself on Networking

A free test with instant, explained results. No account needed.

Start free test
All Networking questions →