I'm using file_get_contents
to make a request to a url. This request may return a 422
error. When this 422
error is returned, I need to capture the body, which comes in JSON
format. However, file_get_contents
does not seem to be able to return content when the request returns an error code.
The message returned is as follows:
Failed to open stream: HTTP request failed! HTTP / 1.1 422 Unprocessable Entity
When this Warning is generated, file_get_contents
returns FALSE
, but I need it to return the content that is returned by the url, even if it has an error code.
How do I file_get_contents
ignore errors and return content to me?
For example (using link to return an error on purpose):
file_get_contents('https://httpbin.org/status/422')