I am trying to send a POST request to a controller with JSON payload. Relevant request details are as follows.
Request URL:http://mag.local/index.php/shahal/test/saveJson
Request Method:POST
Content-Type:application/json
Payload
{"name":"shahal","form_key":"3j7DhIGtPqIRkpyD"}
Rather than going to appropriate controller, it redirect the request to the dashboard. I assume its because Magento doesn't decode JSON string and read the form_key
from the request body. Is there any other workaround for this issue? Or is there a straightforward method for JSON requests in magento?
IMPORTANT
I cannot change the structure of the incoming requests.
Best Answer
Not changing the input is really hacky, because the mistake is made by the form of the request.
That said, you can implement an observer before the check (predispatch?) and get the form_key from the json and put it into the request parameters.