简体   繁体   中英

Java jsoup login to a site

        <div class="mainLoginLeftPanel_signin">
            <label for="steamAccountName">Steam username</label><br>
            <input class="textField" type="text" name="username" id="steamAccountName" maxlength="64" tabindex="1" value=""><br>&nbsp;<br>
            <label for="steamPassword">Password</label><br>
            <input class="textField" type="password" name="password" id="steamPassword" autocomplete="off" maxlength="64" tabindex="2"><br>

Since you can't emulate key-pressing in jsoup is there away to somehow login into a site? maybe somehow setting your cookie?

After getting the the users credentials, you could then try doing an HTTP Post Request to steam via Java.

Since I have never actually tried doing an HTTP Request in Java, I can't tell you how to do it. But this looks promising Sending HTTP POST Request In Java

Quickly taking a look at the Steam site, their login form looks something like this.

<form name="logon" action="" method="POST">
    <div class="login_row">
        <div class="input_title">Steam account name</div>
        <input class="text_input" type="text" name="username" id="input_username" value="">
    </div>
    <div class="login_row">
        <div class="input_title">Password</div>
        <input class="text_input" type="password" name="password" id="input_password" autocomplete="off"/>
    </div>
</form>

And from that I gather you must supply 'username' and 'password' in your Post Request to ' http://store.steampowered.com/ '.

After doing the post request, you could then use JSoup too tell if the login was successful based on the page result.

I hope this helps you. Feel free to comment any questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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