I want to make HTTPS request through PHP to a server and get the response.
something similar to this ruby code
http = Net::HTTP.new("www.example.com", 443)
http.use_ssl = true
path = "uri"
resp, data = http.get(path, nil)
Thanks
this might work, give it a shot.
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); // Set so curl_exec returns the result instead of outputting it. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Get the response and close the channel. $response = curl_exec($ch); curl_close($ch);
for more info, check http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
The Zend Framework has a nice component called Zend_Http_Client which is perfect for this kind of transaction.
Under the hood it uses curl to make requests, but you'll find Zend_Http_Client has a much nicer interface to work with and is easier to configure when you want to add custom headers or work with responses.
If all you want to do is retrieve the page contents with minimal work, you may be able to do the following, depending on your server's configuration:
$data = file_get_contents('https://www.example.com/');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With