我正在用ktor客户机(ApacheHttpClient引擎)创建简单的HTTP请求。
val client = HttpClient(Apache) {
engine {
followRedirects = false
this@HttpClient.expectSuccess = false
}
}并使用它提交一份表格
client.submitForm<HttpResponse>(
url = "https://foo.com/login",
formParameters = Parameters.build {
append("_username", username)
append("_password", password)
})在日志中,我可以看到一个正确的响应302-重定向,我想要从它获得一个cookie。但是,相反,我看到客户机继续前进,提出了几个请求,最后失败了:
io.ktor.client.features.SendCountExceedException:最大发送计数超过20
如何在ktor-客户机中完全禁用基于302的重定向?
发布于 2019-05-28 10:15:40
客户端默认情况下遵循重定向,防止无限重定向使用:
val client = HttpClient(HttpClientEngine) {
followRedirects = false
}https://stackoverflow.com/questions/56309654
复制相似问题