HttpCookies

预计阅读时间: 1 分钟

This feature keeps cookies between calls or forces specific cookies.

本特性在 io.ktor.client.features.defaultRequest 方法中定义,无需任何额外构件。

Installation

val client = HttpClient(HttpClientEngine) {
    install(HttpCookies) {
        // Will keep an in-memory map with all the cookies from previous requests.
        storage = AcceptAllCookiesStorage()
        
        // Will ignore Set-Cookie and will send the specified cookies.
        storage = ConstantCookieStorage(Cookie("mycookie1", "value"), Cookie("mycookie2", "value"))
    }
}
client.cookies("mydomain.com")