因此,我尝试将以下表单中的值发布到 cURL url(脚本名称为 pagination.php),如下所示:
<form action="pagination.php" method="post">
<input style="width:50%" type="text" name="search_term">
<input type="submit" value="Submit">
</form>
$search_term = $_POST['search_term'];
echo $search_term;
$post_data = array('q' => $search_term);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_URL, 'http://gdata.youtube.com/feeds
/api/videos?q='.urlencode($search_term).'&safeSearch=none&orderby=viewCount&
v=2&alt=json&start-index=1&max-results=50');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$data = json_decode($output,true);
$info = $data["feed"];
$video = $info["entry"];
$nVideo = count($video);
echo "<ul style='float:right'>";
foreach($video as $video) {
echo '<img src="'.$video['media$group']['media$thumbnail'][0]['url'].'"><br><br>';
$title = $video['title']['$t'];
$video_id = $video['media$group']['yt$videoid']['$t'];
echo '<a href="search_4.php?video_get_id='.$video_id.'">'.$title.'</a>';
echo '<br>';
}
当我像这样运行代码时,什么也没有发生(是的,我回显了 $search_term 以确保它不为空),但是如果我像这样手动为 $search_term 分配一个值
$search term = 'baseball';
一切正常。cURL 是否存在不允许发布数据的内容?谢谢!