Codeigniter 4 redirecting POST request to "/" when call made from cURL |
I am writing an API and one of the methods is a POST that processes the data passed in the call and sets a response status. When I make a call to this method from a website form submission, it works fine, but when I make the same call from the command line via cURL, it redirects to "/". Do you know why that is?
cURL: Code: curl --location --request POST \ Method: PHP Code: namespace App\Controllers; For reference, I have this route set in Routes.php: PHP Code: $routes->post('api/test', 'Api::test'); I posted the same question on StackOverflow, but thought I might have better luck here: https://stackoverflow.com/questions/7812...-from-curl
I found the issue! It was the CSRF protection. I just had to update it to exclude API calls:
public $globals = [ 'before' => [ // 'honeypot', 'csrf' => ['except' => ['api/*]], // 'invalidchars', ], 'after' => [ 'toolbar', // 'honeypot', // 'secureheaders', ], ]; |
Welcome Guest, Not a member yet? Register Sign In |