Android

Advanced Android Networking

OkHttp Interceptors, Authentication, Cache, Certificate Pinning, WebSocket, GraphQL with Apollo Client

13 คำถามสัมภาษณ์·
Mid-Level
1

What is an Interceptor in OkHttp?

คำตอบ

An Interceptor is a powerful OkHttp mechanism that allows intercepting, observing and modifying HTTP requests and responses. It executes between the application and the network, allowing adding headers, logging, handling authentication, etc.

2

How do you add an Interceptor to an OkHttpClient?

คำตอบ

Use the OkHttpClient builder with the addInterceptor() method for application interceptors or addNetworkInterceptor() for network interceptors. Interceptors are executed in the order they are added.

3

What is a Logging Interceptor used for?

คำตอบ

The Logging Interceptor (HttpLoggingInterceptor) allows logging all HTTP requests and responses for debugging. You can configure the log level: NONE, BASIC (request line), HEADERS (with headers), BODY (with full body).

4

How do you create an Authentication Interceptor to add a Bearer token?

5

How do you add a custom header to all requests with an Interceptor?

+10 คำถามสัมภาษณ์

เชี่ยวชาญ Android สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี