[英]connecting to api with curl and display
我正在連接到traileraddicts api,但是將頁面加載到服務器時卻收到此消息。
注意:嘗試在第20行的/heima/sth132/.public_html/Lokaverkefnireal/php/trailers.php中獲取非對象的屬性警告:/heima/sth132/.public_html/Lokaverkefnireal/php中為foreach()提供的參數無效/trailers.php,第20行
這是我的代碼,你們能幫我解決這個問題嗎???
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "https://api.traileraddict.com/?featured=yes&count=8");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
// load the previously downloaded XML page
$upcoming = simplexml_load_string($output);
foreach($upcoming->trailer as $x => $updates)
{
echo $updates->title;
echo '<br>';
echo '<span style="font-size:x-small">Source: <a href="'. $updates->link .'">TrailerAddict</a></span>';
echo '<br>';
//now echo the embedded trailer
echo $updates->embed;
echo '<br><br>';
}
?>
您應該將curl url協議從https
更改為http
// set url
//please remove https
curl_setopt($ch, CURLOPT_URL, "http://api.traileraddict.com/?featured=yes&count=8");
問題似乎來自您正在卷曲的URL,請嘗試將https更改為http,這對我有用
curl_setopt($ch, CURLOPT_URL, "http://api.traileraddict.com/?featured=yes&count=8");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.