doujia2021 2016-09-27 09:16
浏览 61

file_get_contents无法打开流

Helloo, all I am trying to call the web service from file on windows server 2008.

I have connected to the server and installed there xampp and placed all the required files.

this is my code to call the webservice.

$result = file_get_contents("http://*******:8055/API.ashx?Method=Departure");
    $json = json_decode($result, true);

    $departure_count = count($json['Response']);

It gives me correct response on localhost but not on server. I have googled and they tell me that I should use cURL instead of file_gets_contents.

Then I used this code:

$url = 'http://*******:8055/API.ashx?Method=Departure';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
$json = json_decode($data, true);
$departure_count = count($json['Response']);

and it also gives me response on localhost but not on server, The address to access the URl is : http://221.120.222.68:8080/wordpress/fare/

When I tried to open $url in browser, it gives me the response

  • 写回答

2条回答 默认 最新

  • dongshuo6503 2016-09-27 09:20
    关注

    As the error message says, the stream (URL) requested cannot be opened.

    There are many possible reasons for this:

    1. base URL is bad.
    2. username and/or password are bad
    3. username/password do not have permission on the server
    4. Your system cannot reach the server (firewall, PHP permissions)
    

    I would use the following strategy to debug:

    1. Dump $url and write it down.
    2. Use a browser with debug tools (eg Firefox/Firebug) and try to access that URL.
    3. Look at the headers returned to see what error the server reports (if any).
    4. Think about why that error is returned...
    
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛