[英]cURL command in 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_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 ?
$postdata = array('source' => 'source', 'conversationId' => '6', 'file_contents' => '@' . realpath('/opt/test.xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.