Hello,
I need to login to a wordpress page, collect some data, then logout.
The data is not available without login so first I need to submit the login page
I checked login page via developer tools and found this posted on the login form:
log: user
pwd: xxxx
rememberme: forever
wp-submit: Log In
redirect_to: https://my.wpsite.com/wp-admin/
testcookie: 1
also there is a cookie set like this:
wordpress_test_cookie=WP%20Cookie%20check
I wrote this code before the HTTP POST request:
msg.payload = {};
msg.payload = {
"log":"user",
"pwd":"xxx",
"rememberme":"forever",
"wp-submit":"Log In",
"redirect_to":"https://my.wpsite.com/wp-admin/",
"testcookie":"1"
}
msg.headers = msg.headers || {};
msg.headers["set-cookie"] = [];
msg.headers["set-cookie"] = [
"wordpress_test_cookie=WP%20Cookie%20check",
"wp_lang=en_US"];
return msg;
Unfortunately site returns "You have to enter a username first"
. This probably means that I cannot post the form successfully.
The form is like this:
<form name="loginform" id="loginform" action="https://my.wpsite.com/wp-login.php" method="post">
<p>
<label for="user_login">Username or Email Address</label>
<input type="text" name="log" id="user_login" class="input" value="" size="20" autocapitalize="off" autocomplete="username" required="required">
</p>
<div class="user-pass-wrap">
<label for="user_pass">My Password:</label>
<div class="wp-pwd">
<div class="user-pass-fields"><input type="password" name="pwd" id="user_pass" class="input password-input" value="" size="20" autocomplete="current-password" spellcheck="false" required="required"><div class="loginpress-caps-lock">Caps Lock is on</div></div>
<button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="Show password">
<span class="dashicons dashicons-visibility" aria-hidden="true"></span>
</button>
</div>
</div>
<p class="forgetmenot"><input name="rememberme" type="checkbox" id="rememberme" value="forever"> <label for="rememberme">Remember Me</label></p>
<p class="submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log In">
<input type="hidden" name="redirect_to" value="https://my.wpsite.com/wp-admin/">
<input type="hidden" name="testcookie" value="1">
</p>
</form>
Do you have any idea how I can login and get the cookie stored there for further http requests?
PS: I can post to the site with this command:
curl -d "log=user&pwd=xxxx&rememberme=forever&wp-submit=Log+In" -c cookies.txt https://my.wpsite.com/wp-login.php
and I can see the login cookie in the cookies.txt file.