Ktor 3.0.0 Help

User agent

The UserAgent plugin adds a User-Agent header to all requests.

Add dependencies

UserAgent only requires the ktor-client-core artifact and doesn't need any specific dependencies.

Install and configure UserAgent

To install UserAgent, pass it to the install function inside a client configuration block. Then, use the agent property to specify the User-Agent value:

import io.ktor.client.* import io.ktor.client.engine.cio.* import io.ktor.client.plugins.* // ... val client = HttpClient(CIO) { install(UserAgent) { agent = "Ktor client" } }

Ktor also allows you to add a browser- or curl-like User-Agent value using corresponding functions:

val client = HttpClient(CIO) { BrowserUserAgent() // ... or CurlUserAgent() }
Last modified: 16 September 2022