如何發佈XML並從響應中獲取響應狀態?如何發佈XML?
我要發佈
<myExampleRequest><myValue>xyz</myValue></myExampleRequest>
到http://domain.com/GetStatus.aspx
的頁面
<myExampleResponse><status>True</status><Message></Message></myExampleResponse>
如何發佈XML並從響應中獲取響應狀態?如何發佈XML?
我要發佈
<myExampleRequest><myValue>xyz</myValue></myExampleRequest>
到http://domain.com/GetStatus.aspx
的頁面
<myExampleResponse><status>True</status><Message></Message></myExampleResponse>
最好不要自己做太多這樣的事情。使用類似HttpClient或libcurl的HTTP客戶端庫。 HttpClient的一些例子可以幫助你開始使用here。
O'Reilly's HTTP: The Definitive Guide非常適合背景。我也喜歡RESTful Web Services(它有用libcurl編寫的例子)。
你需要設置你的Content-type
頭響應爲text/xml,然後回顯你的迴應:
header("Content-type: text/xml");
echo $xml_response;
使用file_get_contents
或cURL將響應處理爲字符串,並使用某種類型的XML解析器(如SimpleXML)解析響應以獲得<status>
。