I want to read a server’s reply for a certain request, modify it to my needs, and send it to the site visitor. get_headers() works perfectly for the headers, but if the requested file is missing (404), and that’s exactly what I want to use, get_file_contents(), readfile() and other functions I’ve tried all break with the warning/error that the file is missing instead of reading the replied stream into a variable.
So what I want is a function similar to get_headers() only for the rest of the data, like a get_data() that doesn’t cancel. Is there such a thing?
Thanks for reading.
Use
curl_exec. It will always return the body unless theCURLOPT_FAILONERRORoption is set toTRUE.Here’s an example:
Wrap this in a function and use it wherever you need to get an HTTP response body in your application.