How do I return JSON in HTTP response? [PHP Code]

To return JSON from the server, you must include the JSON data in the body of the HTTP response message and provide a Content-Type: application/json response header. The Content-Type response header allows the client to correctly interpret the data in the response body. In this JSON response example, we send a request to the ReqBin echo URL and provide the Accept: application/json request header to tell the server that the client is expecting JSON. The PHP code was automatically generated for the JSON Response example.
Loading...