1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

my code is expecting 200 as a response, what causes to get 200 as a response i need to know now, 201 is fine but if its 200 then that response I need to post to other URL..can you tell me how can I get 200 as a response(//curl_setopt($ch, CURLOPT_POST, true); with this also its giving 201 only)
If you can't influence how the server answers it will be best if you adapt your code to allow 201 as well as 200.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.