成功登录并没有为我提供访问其他页面所需的cookie(使用Jsoup) [英] A successful login is not giving me the required cookies to access other pages (using Jsoup)
问题描述
我正在尝试通过编程界面(将Java与Jsoup结合使用)登录到网站并保存响应cookie,以便可以将其传递给以下请求.但是登录后,响应头中没有cookie:(
I am trying to login to a website via the programming interface (using Java with Jsoup) and save the response cookie so I can pass it onto following requests. But there is no cookie in the response header after I login :(
我确实成功登录了,但是响应头中没有cookie.出于调试目的,我从chrome浏览器登录并使用chrome网络标签检查了响应标头,然后单击登录"按钮后,它成功地将我登录到了索引页,但响应标头中没有任何cookie.我知道我需要Cookie来访问其他需要登录的页面,因为它们的请求标头中有一个名为"SESSION ..."的Cookie,并且我从未在响应标头中收到该Cookie.
I did manage to login successfully however there is no cookies in the response header. For debugging purpose I logged in from the chrome browser and checked the response header using chrome network tab and after I click the "login" button it successfully logs me in to the index page but without any cookies in the response header. I know I need the cookies to access other pages that require login because their request header has a cookie called "SESSION..." and I never received that cookie in the response header.
有人可以帮我在这里找到问题吗?我已经发布了代码以在下面登录.这是网站www.lib.uts.edu.au
Would someone please help me identify the problem here? I've posted the code to login below. This is the website www.lib.uts.edu.au
Connection.Reponse res = Jsoup.connect(url)
.data("username", id
, "password", password
, "lt", ltVal
, "_eventId", "submit"
, "sso_submit", "Sign In"
, "rememberMe", "true")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2")
.cookies(cookies)
.method(Method.POST)
.followRedirects(true)
.execute();
推荐答案
我认为您输入的是错误的,通常cookie是在上次调用登录名(加载登录表单的调用)中设置的.
I think you are looking in the wrong call, often the cookie is set in the previous call to the login one (the one that load the login form).
如果您尝试以下代码段:
If you try this snippet of code:
//This url loads the login form
Connection.Response response = Jsoup.connect("https://www.lib.uts.edu.au/auth/login?service=https%3A%2F%2Fwww.lib.uts.edu.au%2Fcas%3Fcas_load_iframe%3D1%26destination%3Ddashboard&iframe=true")
.timeout(300000)
.userAgent("Mozilla/5.0")
.method(Connection.Method.GET).execute();
System.out.println("JSESSIONID=" + response.cookies().get("JSESSIONID"));
您会看到类似的内容:
JSESSIONID=E16B98E972FFF05E9091453C01779E67
我希望您会找到想要的会话cookie,只记得在登录和成功调用中使用该cookie.
I hope you'll have there the session cookie you're looking for, just remember to use that cookie in login and succesive calls.
-编辑--
还有另一个uri可以设置SSESS012 ... cookie,然后重定向到我在原始答案中提到的url,请尝试以下操作:
There is another uri that sets a SSESS012... cookie and then redirects to the url I mentioned in my original answer, please try this:
//Try this other url
Connection.Response response = Jsoup.connect("https://www.lib.uts.edu.au/cas?destination=dashboard&cas_load_iframe=1")
.timeout(300000)
.userAgent("Mozilla/5.0")
.method(Connection.Method.GET).execute();
System.out.println("JSESSIONID=" + response.cookies().get("JSESSIONID"));
System.out.println("SSESS012...=" + response.cookies().get("SSESS012ea49d58f199a67a953e1500684490"));
现在您将看到类似的内容:
Now you'll see something similar to:
JSESSIONID=5466DCD5601415175514AA88FEC967A0
SSESS012...=DfL4tW0xOdfu_9Op52b-z3El3CNG2xxOYZdruuVfWH0
我希望这是您所需要的:)
I hope this is what you needed :)
这篇关于成功登录并没有为我提供访问其他页面所需的cookie(使用Jsoup)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!