Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert PHP code to curl command where only TLSv1 is allowed

Tags:

php

curl

How can I convert this php code to curl command? I want to use this code on linux machine by executing single curl command.

$headers = array(
      "Content-type: text/xml",
      "Content-length: " . strlen($xml)
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10000);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$data = curl_exec($ch);

I tired with this one, but unsuccessful:

curl -X POST -H "Content-type: text/xml" -o output.txt -d "param1=param1&username=username&password=password" https://site.url.com -d @data.xml

Maybe the problem is in the HTTPS because only TLSv1 is allowed on the site.

like image 574
ibedelovski Avatar asked Apr 28 '26 16:04

ibedelovski


1 Answers

In php you would use:

curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_1);

Documentation speaks of more TLS versions:

http://www.php.net/manual/en/function.curl-setopt.php

  • CURL_SSLVERSION_TLSv1_0
  • CURL_SSLVERSION_TLSv1_1
  • CURL_SSLVERSION_TLSv1_2

The TLS versions only work with CURL version 7.34 or newer.

like image 79
Luceos Avatar answered May 01 '26 04:05

Luceos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!