如何使用具有POST请求的JSOUP重定向到主页? [英] How can I redirect to the homepage using JSOUP having POST request?

查看:93
本文介绍了如何使用具有POST请求的JSOUP重定向到主页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望登录使用 JSOUP 登录完成使用发布请求。



对于登录,我写了代码:

  Document doc = Jsoup.connect(http://www.mysite.com / home)
.data(username,myusername)
.data(pass,mypassword)
.userAgent(Mozilla)
。后();

我可以重定向到网站的主页,我通过打印HTML下面的代码。

  System.out.println(doc.html()); 

现在,该网站在用户 login 然后而不是重定向到主页,
他们重定向到要求安全问题答案的页面。



然后在文本框中填写答案并单击提交按钮,它将用户重定向到主页。



现在,当我通过 JSOUP 尝试相同的事情时,上面的代码将我重定向到安全问题页面。 p>

我如何填写安全问题的答案并将其重定向到主页?

我该如何实现这一目标?
在此先感谢。

解决方案

您可以使用隐藏的iframe加载安全问题页面并填写答案在页面中使用js,这将会很复杂,因为在尝试登录之前,您还必须先从用户那里获得安全答案。这是可能的,但我会说它是一个糟糕的设计

I want to login into a website using JSOUP and the login is done using post request.

For login , I wrote the code:

Document doc = Jsoup.connect("http://www.mysite.com/home")
  .data("username", "myusername")
  .data("pass", "mypassword")
  .userAgent("Mozilla")
  .post();

I am able to redirect to the homepage of the website , which I confirmed by printing the HTML by the below code.

System.out.println(doc.html());

Now the website has made enhanced security features , after user login then instead of redirecting it to the homepage, they are redirecting to the page which ask for the answer of the security question.

And after filling the answer in the textbox and clicking on the submit button , it redirects the user to the homepage.

Now when I am trying the same thing through JSOUP, the same above code redirects me to the security question page.

How I can fill the answer of the security question and get redirected to the homepage?

How I can achieve this? Thanks in advance.

解决方案

You can use a hidden iframe to load the security question page and fill the answers using js in the page, It ll be little complicated, as you have to get security answer also from user first, before trying to login. It is possible to do, but i ll say its a bad design,

这篇关于如何使用具有POST请求的JSOUP重定向到主页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆