I am trying to call a web service which basicaly looks like this:
我试图调用一个基本上看起来像这样的Web服务:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'
So this is how i call this web service:
这就是我称之为Web服务的方式:
$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:
所以在这里,我什么都没有,xml_result是空的。这是有趣的部分 - 当我从描述中删除空格时:
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 !
一切都很好,我从网络服务得到答案。还尝试使用chrome rest客户端调用Web服务和描述中的空白区域,一切正常,我有回复。所以这导致我在这里使用Web服务中的空格来处理某种PHP问题。请帮忙 !
UPDATE:
print_r($result)
results in
1
1 个解决方案
#1
This is not a valid URL, spaces must be escaped:
这不是有效的URL,必须转义空格:
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?.
您可能想看一下如何在PHP中正确地对字符串进行URL编码?
#1
This is not a valid URL, spaces must be escaped:
这不是有效的URL,必须转义空格:
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?.
您可能想看一下如何在PHP中正确地对字符串进行URL编码?