简体   繁体   English

如何使用jsoup post请求提交没有按钮名称的表单

[英]how to submit form without a name for the button using jsoup post request

I'm trying to POST data into a website to make a login into the site using Jsoup. 我正在尝试将数据发布到网站,以使用Jsoup登录网站。 This is the html form: 这是html表单:

  <form action="/user/login" method="POST"> <table> <tr> <td><label for="email">E-Mail:</label></td> <td><input name="email" value="" /></td> </tr> <tr> <td><label for="password">Passwort:</label></td> <td><input name="password" type="password" /></td> </tr> <tr> <td><input type="submit" value="Login" /></td> </tr> </table> </form> 

Here is my code: 这是我的代码:

 Connection.Response loginForm = Jsoup.connect(LOGINWEBSITE)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0")
                    .method(Connection.Method.GET)
                    .execute();


            Document login = Jsoup.connect(LOGIN_URL)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0")
                    .data("cookieexists", "false")
                    .data("email", email)
                    .data("password", password)
                    .cookies(loginForm.cookies())
                    .post();

But it doesn't work. 但它不起作用。 For another website I just needed to add a line for the button and it worked. 对于另一个网站,我只需要为按钮添加一行就可以了。 Here it does not work, since the button has no name. 这里它不起作用,因为按钮没有名称。 Basically I want to know how to submit the from. 基本上我想知道如何提交。 How can I resolve this issue? 我该如何解决这个问题? Many thanks. 非常感谢。

Often you need to access the login page with a GET request first to get all needed cookies/tokens for the post request. 通常,您需要先使用GET请求访问登录页面,以获取发布请求所需的所有Cookie /令牌。 I can't check that for you since you did not mention the URL to which you try to connect. 我不能为您检查,因为您没有提到您尝试连接的URL。 In your place I would record the network traffic with the browser developer tools when you manually login. 在您的位置,我会在您手动登录时使用浏览器开发人员工具记录网络流量。 Then analyze the data that actually was sent back and forth. 然后分析实际来回发送的数据。 Usually you can easily identify the necessary tokens/cookies that need to be passed along with the post request for a successful login. 通常,您可以轻松识别需要传递的必要令牌/ cookie以及成功登录的发布请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM