File_get_contents () unanswered - php
I am trying to call a webservice that basically 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 I got nothing, xml_result is empty. And here's the fun part - when I remove the white space from the description:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Somedescription'
Everything is fine, I got a response from the web service. Also tried to call webservice with chrome rest client with space in description and everything is fine, I have an answer. So this leads me to some kind of PHP issue here with spaces in the web service. Please, help!
UPDATE:
print_r($result)
leads to
1
+3
source to share
1 answer
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 encode a URL in PHP? ...
+5
source to share