0

I'm trying to login to Magento 2, with a form which contains a "from_key". I scrape this form_key but I'm not able to successfully login. Has someone any idea how to make this work? This is my code:

        $client = new \GuzzleHttp\Client();
        $jar = new \GuzzleHttp\Cookie\CookieJar();
        $request = $client->request('GET', 'https://www.waiglobal.com/eu_nl/customer/account/login/', [
            'cookies' => $jar,
        ]);

        $content = $request->getBody()->getContents();
        $html = str_get_html($content);

        foreach($html->find('input[name=form_key]') as $rows) {
            $form_key = $rows->value;
        }
        
        $request = $client->request('POST', 'https://www.waiglobal.com/eu_nl/customer/account/login/', [
            "form_params" => [
                "form_key" => $form_key,
                "login[username]" => "username",
                "login[password]" => "password",
            ],
            'cookies' => $jar,
        ]);
        return $jar;

1 Answer 1

0

Try to change the post URL for:

https://www.waiglobal.com/eu_nl/customer/account/loginPost/

It must be enough.

1
  • Thanks! I tried it, and it still returns "invalid form key" through out the header.
    – Antonio
    Jun 2, 2021 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.