REST风格的Web服务以资源为中心,十分适合操作数据,利用了Http是一种程序协议,而不需要Soap。
所以我们可以使用Curl库来向一个Web服务发送一个Post请求,数据是XML格式。
$xml_data = ‘<?xml version=”1.0″ encoding=”utf-8″?>’
.’<TestInfo xmlns=”http://demo.dfe.com”>’
.’<test>’.$info.’</test>’
.’</TestInfo>’;
.’<TestInfo xmlns=”http://demo.dfe.com”>’
.’<test>’.$info.’</test>’
.’</TestInfo>’;
注意加入命名空间xmlns。
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array(‘Content-Type: text/xml’));
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml_data);
$result = curl_exec($ch);
curl_close($ch);
消息头中要加入内容类型为text/xml。