简体   繁体   English

PHP中的cURL不起作用

[英]cURL in php not working

i am not able to fetch the web page content of Google search page, but when i am using curl to get info from an API, it is working fine. 我无法获取Google搜索页面的网页内容,但是当我使用curl从API获取信息时,它工作正常。 i want to get Google page content so later on i can manually extract links from that page. 我想获取Google页面内容,以便以后可以手动从该页面提取链接。 i have tried many times, but unable to get web page content from any URL. 我已经尝试了很多次,但是无法从任何URL获取网页内容。 Presently, i am working with XAMPP software to run PHP codes. 目前,我正在使用XAMPP软件来运行PHP代码。

i am using curl_exec() command. 我正在使用curl_exec()命令。 http://www.php.net/manual/en/curl.examples-basic.php is the source link for the code i tried. http://www.php.net/manual/zh-CN/curl.examples-basic.php是我尝试的代码的源链接。

Please also tell me how to use https:// in xampp software using curl command in php 还请告诉我如何在PHP中使用curl命令在xampp软件中使用https://

Try like this 这样尝试

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.google.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // For HTTPS
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // For HTTPS
$response=curl_exec($ch);
echo $response; // Google's HTML source will be printed
curl_close($ch);

The reason why you were not able to get the source is you were not using the CURLOPT_URL parameter instead it was CURLOPT_FILE . 之所以无法获取源代码,是因为您没有使用CURLOPT_URL参数,而是使用CURLOPT_FILE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM