首页 > 解决方案 > 在本地主机上使用 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 在我的本地主机上工作

标签: curlmampphp-curlmamp-pro

解决方案


推荐阅读