PHP5 无法接收来自其他网站的数据

标签 php ubuntu

我有我的虚拟托管网络服务器。我使用 VirtualBox 安装它,它使用 Ubuntu Server 系统。最近,我需要从 Google Maps Geocode 服务中获取数据。首先,我尝试使用下一个代码:

file_get_contents(URL);

收到超时错误后,我也尝试使用 cURL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://maps.google.com/maps/api/geocode/json?address=" . $gm_address . "&sensor=false");
$result = curl_exec($ch);
curl_close($ch);

再一次,我得到了一个超时错误。

我怀疑 Ubuntu 不允许 PHP 调用其他网站。我不是 Linux 或 Ubuntu 专家,所以我不知道如何处理防火墙设置或允许 PHP 进行这些调用的设置。

简而言之,如何更改允许 PHP 从其他网站获取数据的设置?

最佳答案

试试这个 cURL 代码:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://maps.google.com/maps/api/geocode/json?address=" . $gm_address . "&sensor=false"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); 
curl_close($ch);

文本现在是否出现在 $result 中? ?

关于PHP5 无法接收来自其他网站的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8824589/

相关文章:

python-3.x - 具有 tensorflow 问题的稳定基线

c++ - 如何在 ubuntu 中使用 uchar_t 编译项目

c - 我如何修改线程以打印 "hello world again"?在C中

php - 从不等于 $var 的表结果中选择?

php - Jquery 和 Bootstrap 4 dataTable 删除第 2 页上的行不起作用

php - php中的印度日期和时间

php - 仅执行 PHP 文件 - 在 MySQL 中收集数据

php - jQuery 在前面添加一个自动获取 php 文件数据库

ubuntu - WSL2 : Why do I have to shutdown WSL to restart WSL after restarting PC

android - ubuntu升级到14.04 TLS后eclipse Juno经常自动关闭