Bug #67802 [Opn->Nab]: Streams API cannot return error body/content

From: Date: Thu, 07 Aug 2014 15:12:10 +0000
Subject: Bug #67802 [Opn->Nab]: Streams API cannot return error body/content
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187011@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67802&edit=1 ID: 67802 Updated by: aharvey@php.net Reported by: chad at getfidelis dot com Summary: Streams API cannot return error body/content -Status: Open +Status: Not a bug Type: Bug Package: Streams related Operating System: Linux PHP Version: 5.5.15 Block user comment: N Private report: N New Comment: You can set the ignore_errors context option to always retrieve the body, per http://ca2.php.net/manual/en/context.http.php. Previous Comments: ------------------------------------------------------------------------ [2014-08-07 14:51:43] chad at getfidelis dot com 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 ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67802&edit=1

« previous php.bugs (#187011) next »