如何将此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.
解决方法:
在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或更高版本.