【问题标题】:Cakephp: file_get_contents, curl and HttpSocket do not workCakephp:file_get_contents、curl 和 HttpSocket 不起作用
【发布时间】:2015-04-13 10:43:02
【问题描述】:

我正在使用 Cakephp 2.6.1,我想使用外部 api。为此,我必须请求这样的网址:

$json = file_get_contents($url);
$data = json_decode($json);

我尝试使用 file_get_contents、curl 和 HttpSocket。我有那个错误:

php_network_getaddresses: getaddrinfo failed: Name or service not known

我检查php_info(); and allow_url_fopen 是否开启。

提前感谢任何能给我一些想法的人。

【问题讨论】:

  • Google search results 没有任何帮助?
  • 提交帖子更容易寻找一点...问题似乎来自allow_url_fopen,但对我来说不是:/我不明白。
  • 你是在服务器还是本地机器上?
  • 我在服务器上。该代码在 php 框架之外不再工作......编辑:它看起来像一个 DNS 问题。有人帮我解决吗?

标签: php api cakephp curl file-get-contents


【解决方案1】:

就我而言

php_network_getaddresses: getaddrinfo failed: Name or service not known

它出现是因为我的 dsn 地址不再有效。 我刚刚替换为有效的地址 dns,它可以工作:)

【讨论】:

    【解决方案2】:

    你必须在你的服务器中设置 curl

    点击此链接

    How to enable curl in Wamp server

    【讨论】:

      猜你喜欢
      • 2014-01-19
      • 2016-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-13
      • 1970-01-01
      • 2014-01-19
      • 1970-01-01
      相关资源
      最近更新 更多