如何将此 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);
Run Code Online (Sandbox Code Playgroud)
我厌倦了这个,但没有成功:
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
Run Code Online (Sandbox Code Playgroud)
也许问题出在 HTTPS 上,因为站点上只允许使用 TLSv1。
在 php 中,你会使用:
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_1);
文档谈到了更多的 TLS 版本:
http://www.php.net/manual/en/function.curl-setopt.php
TLS 版本仅适用于 CURL 7.34 或更高版本。