使用Jsoup登录到Asp.net表单的发布方法 [英] Login Post Method to Asp.net form using Jsoup
问题描述
我正在尝试使用以下代码登录 http://www.investabroadproperties.com/网站
I am trying to login to http://www.investabroadproperties.com/ site using following code
Connection.Response loginForm = Jsoup.connect("http://www.investabroadproperties.com/")
.method(Connection.Method.GET)
.execute();
Document document = Jsoup.connect("http://www.investabroadproperties.com/")
.data("ctl00$ctl02$tbEmail", "myemail")
.data("ctl00$ctl02$tbPassword", "mypassword")
.cookies(loginForm.cookies())
.post();
但是我无法登录该网站.通过查看该网站的html源,我看到有一些hidden
字段,如下所示,但其值为空.另外还有一个属性onsubmit="javascript:return WebForm_OnSubmit();"
,我不确定如何使用它.
But I am unable to login to this site. By looking into the html source of the site, I see that there are some hidden
fields as shown below but with empty values. Also there is an attribute onsubmit="javascript:return WebForm_OnSubmit();"
, I am not sure how to use it.
我还看到了这篇文章,但是我无法理解所接受答案中给出的逻辑/代码(可能会有所帮助).
I also see this post, but I couldn't understand the logic/code that is given in the accepted answer (may be that one will help).
有人可以帮我登录该网站吗?
Can anybody help me out that how can I login to the site?
我正在使用java和jsoup.
I am using java and jsoup.
我也尝试了下面的代码,但还是没有运气
I also tried below code but still no luck
Connection.Response loginForm = Jsoup.connect("http://www.investabroadproperties.com/")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1")
.method(Connection.Method.GET)
.execute();
Document doc = loginForm.parse();
Elements hiddenElems = doc.select("input[type=hidden]");
Map<String, String> nameValue = new HashMap<>();
for(Element elem : hiddenElems) {
nameValue.put(elem.attr("name"), elem.attr("value"));
}
Document document = Jsoup.connect("http://www.investabroadproperties.com/")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1")
.data("ctl00$ctl02$tbEmail", "myValidEmail")
.data("ctl00$ctl02$tbPassword", "myValidPassword")
.data(nameValue)
.cookies(loginForm.cookies())
.post();
推荐答案
下图取自我的浏览器开发人员工具.如您所见,您的请求中仍然缺少一些值:
The following image was taken from my browser's developer tools. As you can see, you are still missing some values in your request:
您必须将所有这些值发送到服务器.
You must send all these values to the server.
这篇关于使用Jsoup登录到Asp.net表单的发布方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!