dongyupan4850
2017-03-10 13:03
浏览 60

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

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>

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

图片转代码服务由CSDN问答提供 功能建议

我尝试访问的API已禁用CORS,因此我需要在服务器端请求。 利用React和Axios我正在向本地php文件发出get请求,该文件应该执行cURL,但我只是回来而不是执行

 &lt;?php $  curl = curl_init(); 
 
 ncurl_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; 
?&gt; 
 
&lt; script&gt; 
let info = axios.get('。/ proxy。  php')
 console.log(info.data); 
&lt; / script&gt; 
   
 
 

当这个运行时,我的控制台中只记录了php代码 php脚本触发并回显我想要的数据。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duannaoben8011 2017-03-10 14:55
    已采纳

    Sounds like your environment hasn't got PHP installed.

    Do you have anymore information about it?

    点赞 打赏 评论

相关推荐 更多相似问题