file_get_contents使用直接键入的url而不是自动获取的url

时间:2012-07-26 07:57:50

标签: url static file-get-contents

file_get_contents 我有一个奇怪的情况。 网络服务返回网址,因此使用网址我使用 file_get_contents ()从该网址获取文件内容。

类似的东西:

$url = $result_from_webservice->url;

if( file_get_contents( $url ) ){
    echo 'ok';
}
else{
    echo 'error';
}

代码的结果是“错误”。

所以我试图直接设置 $ url var。我显示了网址结果

echo $result_from_webservice->url;

来自女巫我已经获得了如下网址:     https://site.com/page.php?foo1=bar1&foo2=bar2

然后我使用了直接结果:

$url = 'https://site.com/page.php?foo1=bar1&foo2=bar2';

并且惊讶..有效(result =“ok”)。

然后我尝试应用urldecode,认为我的智能浏览器试图平滑页面内容。

$url = $result_from_webservice->url;
    $url = urldecode( $url );

但没有成功。

我已经允许php打印所有错误,没有错误,没有警告,没有通知。

有人知道这里发生了什么,我该如何解决?

1 个答案:

答案 0 :(得分:0)

尝试在使用之前将URL强制转换为字符串:

$url = (string)$result_from_webservice->url;