将PHP代码转换为curl命令,其中仅允许TLSv1

时间:2014-10-28 15:18:46

标签: php curl

如何将此php代码转换为curl命令?我想通过执行单个curl命令在linux机器上使用此代码。

$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);

我厌倦了这个,但没有成功:

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

问题可能在于HTTPS,因为网站上只允许使用TLSv1。

3 个答案:

答案 0 :(得分:4)

在php中你会使用:

curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_1);

文档提到了更多TLS版本:

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

  • CURL_SSLVERSION_TLSv1_0
  • CURL_SSLVERSION_TLSv1_1
  • CURL_SSLVERSION_TLSv1_2

TLS版本仅适用于CURL 7.34或更新版本。

答案 1 :(得分:1)

如果您想强制curl使用TLSv1,您可以使用the docs中的--tlsv1选项:

-1, --tlsv1

(SSL) Forces curl to use TLS version 1.x when negotiating with a remote TLS server. You can use options --tlsv1.0, --tlsv1.1, and --tlsv1.2 to control the TLS version more precisely (if the SSL backend in use supports such a level of control).

-2, --sslv2

(SSL) Forces curl to use SSL version 2 when negotiating with a remote SSL server. Sometimes curl is built without SSLv2 support. SSLv2 is widely considered insecure.

-3, --sslv3

(SSL) Forces curl to use SSL version 3 when negotiating with a remote SSL server. Sometimes curl is built without SSLv3 support.

答案 2 :(得分:1)

问题与TLS / SSL无关。客户将自动协商TLS。 看起来您需要对POST进行一些xml数据并将您的凭据指定为GET参数。 可以通过将GET参数放入请求URL

来完成

我不确定语法,但试试这个:

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

此外,(上面的消息的小offtopic,但我不能评论它)请不要强制SSL2,SSL3或TLS1.0,因为他们有漏洞。大多数服务器会自动协商最佳版本的TLS。

相关问题