file_get_contents无法打开流:HTTP请求失败! json

时间:2017-03-16 12:47:08

标签: php json warnings file-get-contents

在file_get_content上收到错误,它正在替换&到&因此我得到了错误。我得到的数据是json格式。

原始网址为: xyz.abc.com/index.php/DeviceDetails/GetDeviceHistory?tracking_id=70&start_time=2017-03-05 13:14:50& end_time = 2017-03-08 13:十四点50

<b>Warning</b>:  file_get_contents(http://xyz.abc.com/index.php/DeviceDetails/GetDeviceHistory?tracking_id=70&amp;start_time=2017-03-05 13:14:50&amp;end_time=2017-03-08 13:14:50): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
     in
    <b>/home/abc/public_html/php/service.php</b> on line
    <b>1855</b>
    <br />
    {"Status":"false","message":"No data found"}

请帮我解决此错误

2 个答案:

答案 0 :(得分:0)

使用 http:// https:// 确保您的实际网址开始,并在调用file_get_contents时使用引号

的file_get_contents( “http://your_URL_here”)

答案 1 :(得分:0)

尝试在您的URL上运行PHP html_entity_decode(),然后再将其传递给file_get_contents():http://php.net/manual/en/function.html-entity-decode.php(正如Kuldeep Singh上面所说,请确保您将URL作为字符串传递:D)

我有很多类似的问题。它可能是许多东西,缺少标题,无效的用户代理,错误的php.ini配置等等。

我强烈建议使用cURL库,它允许您自定义请求的标题,端口等,以便您可以正确调试。这是我使用的自定义PHP cURL库:https://gist.github.com/schwindy/e5798405d0b6269945bdf037a58f6a4d

希望其中一些有帮助。祝你好运。

相关问题