1
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $xml_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);

$xml = curl_exec($ch);

if(curl_exec($ch) === false) 
{ echo curl_error($ch); }
else 
{ echo 'Operation completed without any errors'; }

curl_close($ch);
return $xml;

Above code is giving below error.

Unknown SSL protocol error in connection to api.site.com:443

As per suggested by many people that below code will resolve above issue but it is not helping. Still getting same error.

curl_setopt ($ch, CURLOPT_SSLVERSION, 3);

I tried below also as per suggestions but still getting same error.

curl_setopt ($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_SSLv3' );

Please suggest what else I should put in code to fix this error.

Thank you,

Gkra
  • 11
  • 1
  • 2

3 Answers3

1

You just ignored the SSL certificate verification, may be it will help you to resolve the problem, use the code below when requesting with CURL.

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
lloiacono
  • 4,714
  • 2
  • 30
  • 46
parthi
  • 424
  • 1
  • 4
  • 16
  • Ty for your reply but still getting same error even after using above mentioned code. – Gkra Mar 23 '18 at 08:29
1

You could check which TLS version the website uses with curl verbose mode:

curl_setopt($curl, CURLOPT_VERBOSE, true);

Where the output will be like this:

...
SSL connection using TLS1.0 / RSA_3DES_EDE_CBC_SHA1
...

Then set CURLOPT_SSL_CIPHER_LIST like this:

curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, "TLSv1");

Where "TLSv1" is the TLS version the website uses.

Changing SSL version and VERIFY_PEER/HOST in curl options didn't solve my problem, but this approach did.

Belle-P
  • 51
  • 4
  • Using PHP curl, where does this output show up? I'm using CURLOPT_RETURNTRANSFER, true, and added CURLOPT_VERBOSE, true, and sending a head request with CURLOPT_NOBODY, true, but the call to curl_exec returns an empty string, and curl_getinfo() does not produce it. – sootsnoot May 03 '23 at 16:50
  • Oops, I see this is answered [here](https://stackoverflow.com/a/14436877/467590) – sootsnoot May 03 '23 at 16:55
0

You may try this code.

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $xml_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_HEADER, false);

$xml = curl_exec($ch);

if($xml === false) { 
    echo curl_error($ch); 
}else{ 
    echo 'Operation completed without any errors'; 
}
curl_close($ch);
return $xml;

Also you may use this class for curl request,

https://gist.github.com/sourovroy/1fba93188470bbe3eefa15cd17533b23