Avoid 302 response code when setting the Location header in PHP
I need to put a “201 Created” Response code and a Location header for a POST request, but for some reason I am still getting a 302 response.
This is what I have:
header('HTTP/1.1 201');
header("Location: ..."); // The new resource URL
header('Content-type: application/json; charset=utf-8');
echo $response;
exit;
I have tried removing the content type, the echo and the exit without any luck, still getting the 302. I read that I need to specify both headers, but that’s what I am doing and no luck. I also tried with:
header("Location: ...", TRUE, 201);
Nothing, still got 302
Does anybody knows what I am not seeing?
Thanks.
Total Views: 7 Today Views: 0














