I'm using this cURL command in command line and it works.
curl --data-binary @/opt/test.xml http://xxxxxxxxxxx/gateway/submit?source=source&conversationId=3039350
But how do I execute this using PHP cURL?
I tried this:
$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 { ... }
How to include --data-binary @/opt/test.xml in PHP cURL?
$postdata = array('source' => 'source', 'conversationId' => '6', 'file_contents' => '@' . realpath('/opt/test.xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.