post的数据为xml字符串,通过 $xml = simplexml_load_string($post_data);转换成xml对象
$header[] = "Content-type: text/xml";//定义content-type为xml $post_data = ' '; $post_data .= ''; $post_data .= '' . 123 . ' '; $post_data .= '' . 测试数据 . ' '; $post_data .= '' . 2016-10-30 18:08:30 . ' '; $post_data .= '' . 2016-10-30 19:08:30 . ' '; $post_data .= ''; // dump($post_data); /*$xml = simplexml_load_string($post_data); dump($xml); echo " "; echo "发送
"; dump($xml);*/ $url = "http://test.api.com"; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // post数据 curl_setopt($ch, CURLOPT_POST, 1); // post的变量 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $response = curl_exec($ch); if (curl_errno($ch)) { print curl_error($ch); } curl_close($ch); $xml = simplexml_load_string($response); echo "接收
"; //dump($response); dump($xml);