dtv7174 2015-05-12 12:07
浏览 24
已采纳

file_get_contents()没有响应 - php

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
  • 写回答

1条回答 默认 最新

  • dongliugu8843 2015-05-12 12:08
    关注

    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?.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度