1

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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