How do I post a XML and get the response status from the response?
I want to post
<myExampleRequest><myVa开发者_Go百科lue>xyz</myValue></myExampleRequest>
to http://domain.com/GetStatus.aspx
The page responds with
<myExampleResponse><status>True</status><Message></Message></myExampleResponse>
It's best not to do too much of this yourself. Use an HTTP Client library like HttpClient or libcurl. Some examples of HttpClient that might help you get started are here.
O'Reilly's HTTP: The Definitive Guide is great for background. I also like RESTful Web Services (which has examples written in libcurl).
You would need to set your Content-type
header to text/xml, then echo out your response:
header("Content-type: text/xml");
echo $xml_response;
Use file_get_contents
or cURL to process the response into a string, and use some sort of XML parser like SimpleXML to parse the response to get <status>
.
精彩评论