3

I am trying to call a web service which basicaly looks like this:

http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'

So this is how i call this web service:

$endpoint = "http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'";

    $opts = array('http' =>
            array(
                    'method' => 'GET',
                    'header'  => 'Content-type: application/xml'
            )
    );

    $context  = stream_context_create( $opts );

    $result = file_get_contents( $endpoint, false, $context );
    $xml_result = simplexml_load_string( $result );
    echo $xml_result->success;

So here, i got nothing, the xml_result is empty. And here is the interesting part - when i remove the blank space from the description:

 http://10.10.10.10:8080/gw/someAction?amount=10&description='Somedescription'

Everything is just fine, I got the answer from the web service. Also tried to call the web service with the chrome rest client WITH the blank space in the description and everything is OK, i have response. So this leads me to some kind of PHP problem here with the blank spaces in the web service. Please, help !

UPDATE:

print_r($result)

results in

1
Alexander Nikolov
  • 1,871
  • 7
  • 27
  • 49

1 Answers1

5

This is not a valid URL, spaces must be escaped:

http://10.10.10.10:8080/gw/someAction?amount=10&description='Some%20description'

You might want to take a look at How to properly URL encode a string in PHP?.

Community
  • 1
  • 1
Werner Henze
  • 16,404
  • 12
  • 44
  • 69