【问题标题】:file_get_contents() with no response - phpfile_get_contents() 没有响应 - php
【发布时间】:2015-07-23 07:11:18
【问题描述】:

我正在尝试调用一个基本上如下所示的 Web 服务:

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

所以我就是这样称呼这个网络服务的:

$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;

所以在这里,我什么都没有,xml_result 是空的。这是有趣的部分 - 当我从描述中删除空格时:

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

一切都很好,我从网络服务中得到了答案。还尝试使用描述中的空白区域使用 chrome rest 客户端调用 Web 服务,一切正常,我有响应。因此,这导致我在这里遇到某种 PHP 问题,其中包含 Web 服务中的空格。请帮忙!

更新:

print_r($result)

结果

1

【问题讨论】:

    标签: php web-services


    【解决方案1】:

    这不是一个有效的 URL,必须转义空格:

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

    您可能想看看How to properly URL encode a string in PHP?。

    【讨论】:

    • 没有工作..alto 尝试 urlencode() 没有成功。
    • rawurlencode() 仅对描述参数起作用
    猜你喜欢
    • 2013-09-10
    • 1970-01-01
    • 2011-08-27
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 2021-06-30
    相关资源
    最近更新 更多