Need response body of HTTP 500 with file_get_contents (PHP)
Asked Answered
S

1

28

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.

Schadenfreude answered 18/5, 2011 at 6:57 Comment(2)
file_get_contents should give you the response body. Can you show some code?Corporator
echo file_get_contents($url, false, $context); will generate a PHP warning reporting the 500 but doesn't return anything.Schadenfreude
C
67

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);
Courtney answered 18/5, 2011 at 7:2 Comment(3)
ignore_errors is the solution here.Warring
to your question of nusoap... yes, that was the first try. Doesn't do 1.2 unfortunately. Literally wrote this script 5 times before getting something that worked. Even tried WSO2's WSF/PHP which appeared to be the most complete lib. Only lib advertised to support everything we needed, but didn't fully deliver.Schadenfreude
Bam. Exactly what I needed.Dogeatdog

© 2022 - 2024 — McMap. All rights reserved.