php - curl 在我的共享主机上无法正常工作
问题描述
我的问题是curl
在我的主机上没有以正确的方式工作,但在我的本地主机上运行良好。
这是我用来测试的代码:
$url = 'https://www.instagram.com/nasa/?__a=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
curl_close ($ch);
echo style_print_r( $result );
在我的托管中,它似乎尝试加载整个页面:(
如何解决这个问题?
解决方案
请检查您共享主机中的 Curl
如果您想检查您使用的托管服务是否已激活 CURL,请创建一个包含以下内容的 php 文件:
<?php
// Script to test if the CURL extension is installed on this server
// Define function to test
function _is_curl_installed() {
   if (in_array ('curl', get_loaded_extensions())) {
       return true;
   }
   else {
       return false;
   }
}
// Ouput text to user based on test
if (_is_curl_installed()) {
 echo "cURL is <span style=\"color:blue\">installed</span> on this server";
} else {
 echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
}
?>
您可以使用任何文件名保存文件,例如 curl.php,保存后,请通过 Web 浏览器访问它,例如在地址www.yourdomain.com/curl.php以查找结果。
推荐阅读
- r - ggplot2中两条密度曲线的单独stat_density
- python - 从 / 导入 Python 文件
- javascript - D3 数据显示的差异
- azure - 当服务计划位于不同的资源组中时如何部署 Azure Functions 应用程序
- c# - 了解 Odata 更新查询
- javascript - Vuetable 2 不在浏览器中显示
- php - 如何在 PHP 中发布 iframe 代码
- sql-server - SQL Pivot(?) - 展平按天/事件选择以包含整周的列
- python - 为什么 HITBTC V2 REST API 返回 2001 错误(不正确的对)?
- excel - 计算特定日期条件内的出现次数