'Log-in to Wordpress from google app script

I'm logging-in Wordpress account from google app script.

This is my try:

var url='http://www...it/wp-login.php';
var options = {
  "method": "post",
  "payload": {
    "log": "user",
    "pwd": "password",
    "wp-submit": "Login",
    "testcookie":'1',
  },
  "followRedirects": false,
};
var response = UrlFetchApp.fetch(url,options);

I get 200 code, instead of expected 302 code.

Where I get wrong?

Other solutions, such as this, give me 404 error code.



Solution 1:[1]

The 200 response code indicates that your request to fetch the desired URL was performed succesfully, while the 302 code means that you are redirected.

The Wordpress login page will redirect you, if your log-in credentials are correct.

In other words - your request is not correct. The sample you are referring to is valid for an ADMIN logging into the ADMIN log-in URL. Is this also your case? Can you log-in manually if you open the URL and use the same credentials as in your Apps Script code?

Solution 2:[2]

Just went through this in case someone else stumbles upon this question.

Things to check:

wp-submit: "Log In" or "Log+In"

Might need redirect_to field

It didn't work without passing Referer: header (doesn't seem t validate this)

Also you need to handle cookies, wp-login sets wordpress_test_cookie=WP+Cookie+check

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ziganotschka
Solution 2 user13825203