💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
对于一些程序,可能需要判断来源网址,如果发现referer不是自己的网站,则拒绝访问,这时候,就需要添加`CURLOPT_REFERER`参数,模拟来路,使得程序能够正常采集。 ~~~ <?php $keyword = 'PHP cURL'; // 参数方法一 // $post = 'wd=' . urlencode($keyword); // 参数方法二 $post = array( 'wd' => urlencode($keyword), ); $url = 'http://demo.zjmainstay.cn/php/curl/search_refer.php'; $refer = 'http://demo.zjmainstay.cn/'; //来路地址 // 执行请求 $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回数据不直接输出 curl_setopt($ch, CURLOPT_REFERER, $refer); //来路模拟 curl_setopt($ch, CURLOPT_POST, 1); //发送POST类型数据 curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //POST数据,$post可以是数组,也可以是拼接 $content = curl_exec($ch); //执行并存储结果 curl_close($ch); ~~~