您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
php通过curl发送xml数据到接口(微信接口为例)
发布时间:2017-06-01 21:01:29编辑:雪饮阅读()
//发送xml数据
function xmlSend($url,$xmlData){
$header[] = "Content-type: text/xml"; //定义content-type为xml,注意是数组
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);
$response = curl_exec($ch);
if(curl_errno($ch)){
print curl_error($ch);
}
curl_close($ch);
return $response;
}
关键字词:php,发送,xml