Skip to content

Instantly share code, notes, and snippets.

@byronhe byronhe/https_client.php
Last active Dec 29, 2015

Embed
What would you like to do?
https client
<?php
$url="https://weixin.qq.com";
$url="https://www.alipay.com";
$url="https://www.baidu.com";
// Initialize session and set URL.
$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);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_FALSESTART, 1);
curl_setopt($ch, CURLOPT_SSL_ENABLE_ALPN, 1);
// CURLOPT_CAINFO is auto detected,see http://docs.guzzlephp.org/en/latest/request-options.html#verify
// https://github.com/dropbox/dropbox-sdk-php/blob/master/lib/Dropbox/Curl.php
for($i=0;$i<10;++$i){
// Get the response and close the channel.
$response = curl_exec($ch);
if($response){
echo $response;
}else{
echo "GET ",$url," failed.\n";
}
}
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.