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

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

报告相同问题?

悬赏问题

  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题