2011-08-18 24 views
0

我想提出一個簡單的PHP REST服務,我打電話,捲曲這裏這項服務是該如何使PHP REST服務器發送效應初探回客戶端

//client code example 

$ch = curl_init($URL); 
//curl_setopt($ch, CURLOPT_MUTE, 1); 

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 

curl_setopt($ch, CURLOPT_POST, 1); 

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 

curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

$output = curl_exec($ch); 

現在對REST服務我收到的代碼請求並執行任務。然後我必須將回復發送回去。

//server code example 

    $xml_post = file_get_contents('php://input'); 

    $xmlparser = new XMLParser; 

    $parsedata = $xmlparser->parse($xml_post); 

    $resultobj = new ResultGenerate; 

    $result = $resultobj->generate($parsedata); 

我不知道如何發送reponse($ result)back.So那$輸出在最後有xml字符串。請幫忙

回答

2
echo $result 

是你所需要的。像這樣想一想。當使用PHP爲網頁提供服務時,您所做的只是爲網頁瀏覽器提供響應。你在那裏使用echo,就像你在這裏使用echo一樣。

相關問題