OKHttp句柄302 [英] OKHttp handle 302
本文介绍了OKHttp句柄302的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次我在此网站上执行OKHttp Post请求时,响应代码为302,响应正文是:
Every time I perform a OKHttp Post request on this site, the response code is 302 and the response body is:
<html>
<head>
<title>Object moved</title>
</head>
<body>
<h2>Object moved to <a href="/GradebookSummary.aspx">here</a>.
</h2>
</body>
</html>
这是我的代码:
OkHttpClient client = new OkHttpClient().newBuilder()
.followRedirects(false)
.followSslRedirects(false)
.build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "checkCookiesEnabled=true&checkMobileDevice=false&checkStandaloneMode=false&checkTabletDevice=false&portalAccountUsername=username&portalAccountPassword=password");
Request request = new Request.Builder()
.url("https://hac.chicousd.org/LoginParent.aspx?page=GradebookSummary.aspx")
.post(body)
.addHeader("content-type", "application/x-www-form-urlencoded")
.addHeader("cache-control", "no-cache")
.build();
Response response = client.newCall(request).execute();
我的问题是:如何处理回复以便能够转到新位置?
My question is: How could I handle the response to be able to go to the new location?
推荐答案
All I needed to do was add a persistent cookie handler, which I found here.
这篇关于OKHttp句柄302的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文