Reputation: 43
I am getting CURLINFO_HTTP_CODE as 201 but I need 200. What is the reason that it is returning 201 instead of 200? Please help me on thins.
Here is my code
$ch = curl_init(URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_COOKIEFILE, QC_COOKIES);
curl_setopt($ch, CURLOPT_COOKIEJAR, QC_COOKIES);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type: application/json; charset=utf-8","Accept:application/json, text/javascript, */*; q=0.01"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp=curl_exec($ch);
$httpcode=curl_getinfo($ch, CURLINFO_HTTP_CODE);
Thanks.
Upvotes: 1
Views: 7739
Reputation: 17797
Quote from the w3c documentation:
CREATED 201
Following a POST command, this indicates success, but the textual part of the response line indicates the URI by which the newly created document should be known.
So, the webserver answers successful POST requests with a 201 status code. If you want to get a 200 status code you have to make a GET request by removing this line:
//curl_setopt($ch, CURLOPT_POST, true);
But there is nothing wrong with the 201 answer, you can just accept it as well.
Upvotes: 1