The 4xx
HTTP status codes mean "Client error".
More specific, the meaning of the 400 status code is "Bad request". This means the HTTP request is malformed and the server (or the server-side script that processes it) does not understand it.
The documentation of file_get_contents() explains:
The function returns the read data or FALSE
on failure.
A status code different than 200
is a failure.
There is a way to get the body of the request instead of FALSE
on errors. All you have to do is to create a stream context, configure it to ignore the HTTP errors and pass it as the third argument to file_get_contents()
$url = 'http://localhost/';
$options = array(
'http' => array(
'ignore_errors' => true,
),
);
$context = stream_context_create($options);
$data = file_get_contents($url, false, $context);
$data
now contains the body of the response but you have to parse $http_response_header[0] to know if the request was successful or not.
Anyway, a status code of 400
means an error in the code that issues the request; you should fix the request (probably you submit a body).