
HTTP Client
http.Client, requests, timeouts, transport, redirects, cookies, custom headers
1What is the main difference between http.Get and http.Client.Get?
What is the main difference between http.Get and http.Client.Get?
Câu trả lời
http.Get uses a default HTTP client (http.DefaultClient) that offers no customization, while http.Client.Get allows configuring parameters like timeouts, redirect policies, or custom transport. In production, it is recommended to create a custom HTTP client to control request behavior and avoid indefinite blocking.
2What happens if http.Client.Timeout is not set?
What happens if http.Client.Timeout is not set?
Câu trả lời
Without an explicit timeout, the HTTP client waits indefinitely for the server response, which can block the application if the server doesn't respond. The default timeout is zero, meaning no time limit. Always set a reasonable timeout in production to avoid blocked goroutines and resource leaks.
3How to add custom headers to an HTTP request?
How to add custom headers to an HTTP request?
Câu trả lời
Custom headers are added via http.Request.Header.Set() or Header.Add() after creating the request with http.NewRequest. The Set method replaces existing values while Add appends a new value for the same key. This approach is necessary for authentication, content negotiation, or tracking requests with custom identifiers.
Why is it important to call response.Body.Close()?
Which HTTP method allows sending JSON data to the server?
+15 câu hỏi phỏng vấn
Các chủ đề phỏng vấn Go khác
Go Basics
Go Data Structures
Go Interfaces
Error Handling
Goroutines Basics
Channels
Go Modules
HTTP Server
JSON Encoding
database/sql
Context Package
Testing
Concurrency Patterns
Sync Primitives
Go Web Frameworks
REST API Design
gRPC
Reflection
Memory Management
Performance Optimization
Generics
Go Design Patterns
Microservices
Security & Authentication
Docker & Containerization
Kubernetes Basics
Advanced Go
CLI Development
Nắm vững Go cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí