amin365
amin365

Reputation: 196

PHP cURL not rendering requested webpage

I am trying to figure out if my server can make outbound https request(more specifically port 443) by using cURL, but the code is neither loading any page content nor giving any error.

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
$response = curl_exec($ch);
echo $response;

// close cURL resource, and free up system resources
curl_close($ch);
?>

I am new to the use of cURL, but shouldnt it load the content of google's home page?

Upvotes: 0

Views: 241

Answers (2)

rain
rain

Reputation: 243

If you want to send request to https server,sometimes you also need these two options:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

Upvotes: 0

user557846
user557846

Reputation:

to actually get the response you must add:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

don't scrape google, even to test, they actively detect and stop this

Upvotes: 1

Related Questions