Redirect

预计阅读时间: 1 分钟

By default, Ktor HTTP client does follow redirections; this feature allows to follow Location redirects in a way that works with any HTTP engine. Its usage is pretty straightforward, and the only configurable property is the maxJumps (20 by default) that limits how many redirects are tried before giving up (to prevent infinite redirects).

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

Install

This feature is installed by default.

Prevent installing

val client = HttpClient(HttpClientEngine) {
    followRedirects = false
}

This feature is included in the core of the HttpClient so it is available always along the client.