我正在向API提交CURL Post请求,该请求在成功时返回带有URL的“201 Created”状态 标题的 我不确定它的状态代码是201,还是请求方法需要 从 作为最后的手段,我考虑过简单地解析标题并创建一个新的CURL请求,但这不是最佳的,我猜我只是缺少一些简单的东西来使其按预期工作。 p>
如何让CURL自动关注并提交 LOCATION code>部分中的资源。 我想要的是自动检索新创建的资源,但到目前为止还没有这样做。 我已经尝试设置
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,true); code>但无济于事。 值得注意的是资源确实需要
GET code>请求。 p>
POST code>更改为
GET code>,但由于某种原因,它不遵循
LOCATION code>标头。 获取
curl_getinfo($ ch,CURLINFO_EFFECTIVE_URL); code>似乎确认这一点,因为结果与原始URL相同,而不是新的
LOCATION code>。 p>
\ n
GET code>请求到以201响应返回的
LOCATION code>? p> \ n div>
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?