|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-08-07 15:12 UTC] aharvey@php.net
-Status: Open
+Status: Not a bug
[2014-08-07 15:12 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 17:00:02 2025 UTC |
Description: ------------ I have been unable to find any way to access body content using the HTTP stream wrapper, if the response contained an HTTP error code. I'm trying to contact a REST API that returns useful error data in the body (pinpointing, for instance, _which parameter_ is incorrect and what the proper range or format for its value is) with error codes 400 and up. When this error code is returned, fopen() returns FALSE, and it's not possible to access the response. $http_response_header contains the *headers* but not the body. All of the stream functions require a resource, which fopen() clearly didn't return, and substituting a context passed to the fopen() call also fails (which I expected, but tried anyway.) There does not seem to be any sort of stream_get_last_error() function, either. I can pull this off with cURL of course, but the streams API is generally more convenient to use. Test script: --------------- <?php # I can't give you my password for the API, so I'll use google... $fp = fopen("https://www.google.com/please-404-forever?thanks=1", 'r'); print_r($http_response_header); # does not have body print_r(array_keys($GLOBALS)); # no useful vars present if ($fp) echo 'got a stream', PHP_EOL; # never runs ?>