The UserAgent plugin adds a User-Agent
header to all requests.
UserAgent
only requires the ktor-client-core artifact and doesn't need any specific dependencies.
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.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()
}