Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 988 Bytes

user-agent.md

File metadata and controls

34 lines (22 loc) · 988 Bytes

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

Add dependencies {id="add_dependencies"}

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

Install and configure UserAgent {id="install_plugin"}

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()
}