I am submitting a CURL Post request to an API which, upon success, returns status "201 Created" with the URL of the resource in the LOCATION
part of the header. What I'd like is to automatically retrieve the newly created resource but so far haven't been able to do so. I've tried setting curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
but to no avail. it's worth noting that the resource does require a GET
request.
I'm not sure if it's the status code being a 201, or if the request method needs to change from POST
to GET
, but for some reason it's not following the LOCATION
header. Fetching curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
seems to confirm this as the result is the same as the original URL, not the new LOCATION
.
As a last resort I have considered simply parsing the headers and creating a new CURL request, but this would not be optimal and I'm guessing that I'm just missing something simple to make this work as desired.
How can I get CURL to automatically follow and submit a GET
request to the LOCATION
returned with a 201 response?