Magento 2 - How to enable POST request on Controller without X-Requested-With: XMLHttpRequest
I wrote these tutorials for myself in future when I forget for the next steps.
Search for a command to run...
I wrote these tutorials for myself in future when I forget for the next steps.
No comments yet. Be the first to comment.
When you provision an Ubuntu instance on Oracle Cloud, you'll notice something different from standard Ubuntu installations: the system uses iptables instead of ufw for firewall management. This disti

When developing web applications locally, HTTPS is often overlooked. Yet, modern browsers and APIs increasingly require secure connections—even in development. That’s where mkcert comes in: a simple t

Testing the checkout success page in Magento 2 can be frustrating. By default, once an order is placed, Magento clears the quote session, meaning you can’t simply refresh or revisit the success page without going through the entire checkout process a...

Magento Commerce (EE) offers powerful features, but for many teams, Open Source (CE) is leaner, lighter, and more sustainable. If you're migrating from EE to CE, the Opengento downgrade tool provides a clean, scriptable way to remove proprietary modu...

If you’ve ever checked your Apache error logs and seen something like this: Code [core:error] (13)Permission denied: access to /robots.txt denied (filesystem path '/home/username/sites') because search permissions are missing on a component of the pa...

By Default, if you want to request thru post method, you need to need to decide this on Header Request :
X-Requested-With: XMLHttpRequest
Problem here is, what if we won’t include that header?
Use this classes by putting on top of class
use Magento\Framework\App\CsrfAwareActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\Request\InvalidRequestException;
CsrfAwareActionInterface InterfaceImpletements this interface to the controller :
...
class Paymentflag extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface
{
...
Edit your Controller by adding this methods to allow that request :
public function createCsrfValidationException(RequestInterface $request): ? InvalidRequestException
{
return null;
}
public function validateForCsrf(RequestInterface $request): ?bool
{
return true;
}
Go get the request without header.