Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need response body of HTTP 500 with file_get_contents (PHP)

Using file_get_contents as part of custom SOAP implementation to apply SOAP calls (ALL libraries that we tried would not do SSL + certificate based authentication with SOAP 1.2 correctly). However difficult and barely-documented API often returns 500. There are error details in response body, but file_get_contents doesn't appear to allow access to it. fopen seems to have the same issue.

What do?

Prefer not to go to cURL due to heavy use of stream contexts to get authentication working.

like image 868
frEEk Avatar asked May 18 '11 06:05

frEEk


People also ask

What will the file_get_contents () return?

The function returns the read data or false on failure. This function may return Boolean false , but may also return a non-Boolean value which evaluates to false .

What is the use of file_get_contents in PHP?

The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string. It will use memory mapping techniques, if this is supported by the server, to enhance performance.

Which is faster cURL or file_get_contents?

file_get_contents() is slightly faster than cURL.

What is the difference between file_get_contents ($ file and file_get_contents ($ file in PHP?

2 Answers. Show activity on this post. The first two, file and file_get_contents are very similar. They both read an entire file, but file reads the file into an array, while file_get_contents reads it into a string.


1 Answers

You might consider nusoap.

For your question though, it works if you use ignore_errors.

$context = stream_context_create(array(     'http' => array(         'ignore_errors' => true      ) ));  $contents = file_get_contents($url, false, $context); 
like image 62
dtbarne Avatar answered Oct 02 '22 04:10

dtbarne