[英]How to login the website by using the Jsoup library on Android
我试图找到问题的答案。
但是,我无法在我的android应用中登录以下网站。
http://www.ddanzi.com/index.php?act=dispMemberLoginForm
它出什么问题了? 有人可以帮助我找到错误的代码段吗?
下面是我的查询代码。
Connection.Response res = Jsoup.connect("http://www.ddanzi.com/index.php?mid=free&act=dispMemberLoginForm")
.followRedirects(true)
.data("user_id", "myid")
.data("password", "mypassword")
.method(Connection.Method.POST)
.execute();
Document document = Jsoup.connect("http://www.ddanzi.com/index.php?act=dispMemberInfo")
.followRedirects(true)
.cookies(res.cookies())
.method(Connection.Method.POST)
.post();
我花了大约3个小时来找出解决方法........ :-(
不要在第一次请求时发送用户名和密码。 第一个请求旨在为您获取Cookie(有时还需要登录其他字段)。 发出第一个请求,如下所示:
Connection.Response res = Jsoup.connect("http://www.ddanzi.com/index.php?mid=free&act=dispMemberLoginForm")
.followRedirects(true)
.userAgent("Mozilla/5.0") //I use FF, and I want that the app will get exectly the same page as I do
//you may add more headers, as "Accept Encoding" - check it
.method(Connection.Method.GET)
.execute();
现在,您可以发送POST请求。 除了您使用的Cookie之外,它还有更多参数,因此看起来应该像-
Document document = Jsoup.connect("http://www.ddanzi.com/index.php?act=dispMemberInfo")
.followRedirects(true)
.cookies(res.cookies())
.method(Connection.Method.POST)
.data("error_return_url", "/index.php?mid=free&act=dispMemberLoginForm")
.data("mid", "free")
.data("vid", "")
.data("ruleset", "@login")
.data("success_return_url", "")
.data("act", "procMemberLogin")
.data("user_id" ,"user")
.data("password", "password")
.referrer("http://www.ddanzi.com/index.php?mid=free&act=dispMemberLoginForm")
.post();
您也可以在第二个请求中添加诸如“接受编码”的标头。 大多数网站并不介意。
您可以看到浏览器使用内置的开发人员工具发送的exect请求。
正如我所看到的,最重要的是将user agent
更改为“愚弄”该站点,并使其认为您不是从移动设备浏览-它在移动设备上看起来可能有所不同,并请求其他登录信息。
当然,我无法登录到您的站点,因此无法检查以上所有内容。 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.