I sent a “POST” request via external server for version magento-2.3

My internal Magento URL cannot verify and response is

"Invalid Form Key. Please refresh the page."

as a summary, i want to reach to magento-2.3 from outside and is there any valid way to do it ?

Additional information

I'm planning to build a payment module for my Magento store,
So my PSP working with this way;

When the customer clicks pay button of javascript embeded payment form, my PSP POSTing a value to my provided callbackUrl which is my controller inside of my module. (So I'm expecting a POST value to my controller.

It looks like this: https://mywebsite.com/mymodule/response).

When I'm trying to grab the value with this code piece
($postData = $this->getRequest()->getPostValue(); $postData['token']).

When I'm trying to do this, Magento is requesting a value named "form_key". In earlier version there was no usage like this. I'm suspecting there is a change in the Magento 2.3.0.

Can you help me ?


4 Answers 4

protected $request;
protected $formKey;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\Data\Form\FormKey $formKey,
    \Magento\Framework\App\Request\Http $request
) {
    $this->request = $request;
    $this->formKey = $formKey;
    $this->request->setParam('form_key', $this->formKey->getFormKey());

This is an fix, which send form_key in all the requests. The above code will work on Magento 2.3 and below Magento 2.3.

  • In which file do we need to add this code @Arjun Manoharan Sep 9, 2019 at 6:04
  • Please tell me where to add this code @ArjunManoharan Sep 17, 2019 at 12:07
  • 1
    I strongly think this is a bad idea. The form_key was added for security reasons and this will skip the form key check mechanism. Dec 13, 2019 at 5:58

This problem is occurred after adding more custom options and categories in the product so because php.ini file not allowed to add more custom options.

So, we need to change default settings of php.ini file.

If php version 7.1 then,


If php version 7.0 then,


If php version 7.2 then,


Uncomment this value and update this all value in php.ini,

max_input_vars = 200000
max_input_time = 600
max_execution_time = 3600

Then Restart Apache 2 web server, and check it.

sudo service apache2 restart

I am sure that problems came from session storage & cookie setting.

You should follow below:

DELETE FROM core_config_data WHERE path='web/cookie/cookie_domain';

DELETE FROM core_config_data WHERE path='web/cookie/cookie_path';

Delete all directories from below folders:

  • Thanks @hiren-kadivar unfortunately the problem continues. I updated my question. Can you look again? Jan 31, 2019 at 13:08

Increasing max_input_vars has solved the problem in my case:

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.