php xml post curl

/**
* 发送post请求
* @param string $url 请求地址
* @param array $xmldata post数据
* @return string
*/
function send_post($xmldata,$url) {


//初始一个curl会话
$curl = curl_init();
$header[] = "Content-type: text/xml";
//设置url
curl_setopt($curl, CURLOPT_URL,$url);

//设置发送方式:post
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
//设置发送数据
curl_setopt($curl, CURLOPT_POSTFIELDS, $xmldata);

//TRUE 将curl_exec()获取的信息以字符串返回,而不是直接输出
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

//执行cURL会话 ( 返回的数据为xml )
$return_xml = curl_exec($curl);

//关闭cURL资源,并且释放系统资源
curl_close($curl);

return $return_xml;
}
原文地址:https://www.cnblogs.com/leescre/p/8509694.html