curl - 在本地主机上使用 CURL 的 MAMP
问题描述
我正在用 php 编写一个 API。所以这涉及我笔记本电脑上的两个项目。api项目和调用api的项目。
如果我将 API 项目放在生产服务器上,它就可以工作,所以我认为问题出在我的 MAMP Pro 安装上。
phpinfo() 说启用了 CURL 支持 - 版本 7.65.1 我的防火墙被禁用
这是我用 CURL 调用 API 的代码
$url = "http://localhost:8888/MyAPI/api/?endpoint=endpoint1
// $url = "https://www.myliveserver.com/api/?endpoint=endpoint1 /* This works */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->ApiKey ));
/* I have tried these options - still not working */
//curl_setopt ($ch, CURLOPT_PORT , 8888);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch); /** This is the line it gets stuck at - no error, just waits .... */
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlErrorCode = curl_errno($ch);
$curlErrorMessage = curl_error($ch);
curl_close($ch);
如何使 CURL 在我的本地主机上工作
解决方案
推荐阅读
- html - wkhtmltopdf thead 在第二页上重叠内容
- delphi - TOpenDialog 不改变模型级别
- javascript - IE 自动将对象宽度设置为 0
- php - Symfony 将 twig 文件解析为 xml 而不是 html
- c# - 二进制流“226”不包含有效的 BinaryHeader - C#
- python - python不断扫描目录
- c# - 将奇数从数组复制到另一个数组
- laravel - 嵌套循环导致性能下降
- spagobi - 是否可以在 SpagoBI Server 5.2 中编辑数据源数据
- java - 我正在尝试使用 servlet 检索 BLOB 数据(图像)并在 html 页面中显示