如何在cURL上使用TLS协议?

时间:2014-12-10 12:33:34

标签: php ssl curl server

实际上是代码:

$data = '{"params": ["testing_true", "bb4238e7-8f6d-4b2e-9ea4-43791bfb72df"], "jsonrpc": "2.0", "method": "gate.check", "id": 27034}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "tls://site.com");
curl_setopt($ch, CURLOPT_PORT, 4928); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER,      array(                                                                          
'Content-Type: application/json',                                                                                
'Content-Length: ' .    strlen($data)                                                                       
));       

$output = curl_exec($ch);

var_dump(curl_error($ch));

var_dump(curl_errno($ch));

echo($output) . PHP_EOL;

curl_close($ch);

通过这种治疗,我得到了

Protocol tls not supported or disabled in libcurl

这是一个使用TLS的例子,因为它是与cURL交朋友的? How to make TLS connection from PHP in web server, and safely

1 个答案:

答案 0 :(得分:0)

您需要HTTPS://这是HTTP over TLS协议的名称。

所以," https://example.com"等