Yinan Wang
Yinan Wang

Reputation: 173

Return a HTTP 200 Code to the POST client?

I have a server sending POST to me. I need to reply with HTTP 200 OK. Server needs kind of like a "Go Ahead!" prompt before it executes another action. It requires a HTTP 200 response.

EDIT I've tried the header(), but the server for some reason won't read it?

Upvotes: 10

Views: 40976

Answers (2)

Lix
Lix

Reputation: 47956

The 200 code is a standard response to a successful request... Even echoing out an empty json string would result in a 200 OK status.

echo json_encode(array());

If all you want to do is signal to your client that some process was completed, you can just echo back a custom status message or even a blank object like I demonstrated above.

If you want to actually manually send the 200 header you can do so like this -

header('Status: 200');

Make sure that this header is send before you have any output from the server.

Upvotes: 10

Zachary Canann
Zachary Canann

Reputation: 1231

This function call does the job: http_response_code(200);

See: http://php.net/manual/en/function.http-response-code.php

This function call can be thrown anywhere in the server code -- the order of when this function is called does not seem to matter.

Upvotes: 7

Related Questions