我在命令行中使用此cURL命令并且它可以正常工作。
curl --data-binary @/opt/test.xml http://xxxxxxxxxxx/gateway/submit?source=source&conversationId=3039350
但是如何使用PHP cURL执行此操作?
我试过了:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://xxxxxxxx.xxx/xx/xx");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"source=source&conversationId=6");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
// further processing ....
if ($server_output == "OK") { ... } else { ... }
如何在PHP cURL中包含 - data-binary @ / opt / test.xml ?
答案 0 :(得分:0)
$postdata = array('source' => 'source', 'conversationId' => '6', 'file_contents' => '@' . realpath('/opt/test.xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);