PHP cURL中的cURL命令

PHP cURL中的cURL命令,php,curl,Php,Curl,我在命令行中使用这个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_setop

我在命令行中使用这个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 { ... }

如何将--data binary@/opt/test.xml包含在PHP cURL中?

您是否有任何错误?您是否希望将
二进制文件作为
内容传输编码发送
?我阅读了一些文章,其中我将不得不使用application/x-www-form-urlencoded,如果我将其发送为二进制文件data@Scriptable:我没有收到任何错误。但是我需要在PHP cURL中包含test.xml部分
$postdata = array('source' => 'source', 'conversationId' => '6', 'file_contents' => '@' . realpath('/opt/test.xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);