我能够让 api 加载到我的网站上,该网站使用一点 php 来强制执行 https。
基本上,我将 http 站点卷曲并将结果存储在我的域上的一个页面上,该页面是 https,因此它非常适合我。
我写了一个小函数来为我完成这项工作
<?php
#Defining the basic cURL function
function curl($url) {
$ch = curl_init(); // Initialising cURL
#Setting cURL's URL option with the $url variable passed into the function
curl_setopt($ch, CURLOPT_URL, $url);
#Setting cURL's option to return the webpage data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
#Executing the cURL request and assigning the returned data to the $data variable
$data = curl_exec($ch);
#Closing cURL
curl_close($ch);
#Returning the data from the function
return $data;
}
echo $scraped_website = curl("http://www.example.com");
#I use http://api.openweathermap.org/data//2.5/weather?q=Saint+Louis%2C+MO&units=imperial&lang=nl&APPID=b923732c614593659457d8f33fb0d6fd&cnt=6 instead of "http://www.example.com"
?>
#Full sn-p
<?php
// Defining the basic cURL function
function curl($url) {
$ch = curl_init(); // Initialising cURL
curl_setopt($ch, CURLOPT_URL, $url); // Setting cURL's URL option with the $url variable passed into the function
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
$data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
curl_close($ch); // Closing cURL
return $data; // Returning the data from the function
}
echo $scraped_website = curl("http://www.example.com");
?>
enter code here