我能够在命令行上成功运行:
curl -v -H "a-token: myTokenValue" -H "content-type: application/xml" -X POST --data-binary @/tmp/myfile_2_3.xml -A "My Wonderful Agent" http://example.com/url
如何在PHP中获取此功能?
答案 0 :(得分:1)
更新:使用POST和文件上传: - )
$fileContents = file_get_contents("/tmp/myfile_2_3.xml");
$defaults = array(
CURLOPT_CUSTOMREQUEST => "post",
CURLOPT_HEADER => 1,
CURLOPT_URL => "http://example.com/url",
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => $fileContents,
CURLOPT_HTTPHEADER => array("a-token" => "myTokenValue", "Content-Type" => "application/xml"),
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
答案 1 :(得分:0)
将其传递给exec()
。
答案 2 :(得分:0)