来自本地PHP的Axios GET仅返回代码而不是执行

问题描述:

我尝试访问的API已禁用CORS,因此我需要在服务器端进行请求.利用React和Axios,我向本地php文件发出了一个get请求,该文件应该执行cURL,但只是取回php代码而不是执行它

The API I am trying to access has disabled CORS so I need to request on the server side. Utilizing React and Axios I am making a get request to the local php file which should execute cURL but am just getting the php code back instead of it executing

<?php $curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "https://api.darksky.net/forecast/myAPIKet/coords");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);

curl_close($curl)

echo $result;
return;
?>

<script>
let info = axios.get('./proxy.php')
    console.log(info.data);
</script>

当此命令运行时,仅将php代码记录在我的控制台中,而不是触发并回显我想要的数据的php脚本.

When this runs just the php code is logged in my console instead of the php script triggering and echoing the data I want.

听起来好像您的环境尚未安装PHP.

Sounds like your environment hasn't got PHP installed.

您是否有关于它的更多信息?

Do you have anymore information about it?