1
I’m using file_get_contents
to make a request to a url. This request can return an error 422
. When that mistake 422
is returned, I need to capture the body, which comes in format JSON
. But the file_get_contents
seems not to be able to return the content when the request returns an error code.
The returned message is as follows:
Failed to open stream: HTTP request failed! HTTP/1.1 422 Unprocessable Entity
When this Warning is generated, the file_get_contents
returns FALSE
, but I need it to return the content that is returned by the url, even if it has error code.
How do I make to file_get_contents
ignore errors and return me the content?
For example (using the httpbin.org to return an error on purpose):
file_get_contents('https://httpbin.org/status/422')
tries to manually set the Header to 200 :
http_response_code(200)
– Lucas Queiroz Ribeiro
This does not solve the problem, @Lucasqueirozribeiro. This changes the answer sent, not the one I receive in file_get_contents.
– Wallace Maxters