Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return a HTTP 200 Code to the POST client?

Tags:

http

post

php

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?

like image 973
Yinan Wang Avatar asked Aug 18 '12 22:08

Yinan Wang


2 Answers

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.

like image 104
Lix Avatar answered Oct 30 '22 08:10

Lix


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.

like image 35
Zachary Canann Avatar answered Oct 30 '22 09:10

Zachary Canann