如何发布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>
。