我正在尝试使用 CookieJar 将保存的身份验证 cookie 添加到进一步的请求中。虽然获取正确的身份验证 cookie 并将其保存到 jar 中效果很好,但在检查 时response.request().headers(),cookie 无处可寻。
我发现这特别奇怪,因为我通过调试发现loadForRequest()请求调用并返回正确的 cookie。在 Postman 中使用完全相同的 cookie 来伪造请求时,它会返回所需的结果(没有登录表单的页面)。
有人可以尝试解释我缺少什么吗?
使用 jar 的类
class HTMLRoutes {
var scheme = "https"
var host = "www.mangaupdates.com"
val cookieJar = MULoginCookieJar()
var client = OkHttpClient.Builder()
.cookieJar(cookieJar)
.build()
/*Other code*/
private fun getHTMLFromUrl(url: HttpUrl): String {
var request = Request.Builder()
.url(url)
.build()
client.newCall(request).execute().use { response ->
//Right before returning response the loadForRequest() method gets called in the MUCookieJar class
if (response.isSuccessful) { …Run Code Online (Sandbox Code Playgroud)