views:

55

answers:

2

I am using PHP to interact with a Web Service using REST and HTTP GET requests to call on the available APIs to return XML data. When testing via the address bar, I get the expected XML content.

So the next step I tried was to read that XML data or store the values returned into a string. But when I use file_get_contents I don't get anything back. No error messages, no nothing. Just a blank page with no source.

Where am I going wrong?

<?php
$base = 'https://www.example.com/webservice.asmx';
$params = array('ID' => '12345',
                 FirstName' => 'Joe',
         'Surname' => 'Bloggs');
$url = $base . '/IsMember?' . http_build_query($params);

$response = file_get_contents($url);
echo $response;
?>

The XML that should be getting read is:

<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://www.example.com/"&gt;false&lt;/boolean&gt;
A: 

Try doing a var_dump($url) to make sure it's valid, and also do a var_dump($response) to see what comes back (most likely false ...).

Is the web service and that script on the same web server?

xil3
I've done a var_dump($url) and it outputs: string(122) "the url in correct format". The web service and script sit on different servers.
baswoni
If you have access to a shell on the machine hosting the script, try doing a curl to the web service url and see what comes back - it may not be getting through because of a routing/firewall issue.
xil3
A: 

This is just a stab in the dark, but maybe allow_url_fopen is disabled.

This should let you find out:

echo ini_get('allow_url_fopen');
George Marian
I've checked phpinfo() and can see that allow_url_fopen is set to On for both Local and Master values.
baswoni