views:

45

answers:

2
+1  Q: 

How do I post XML?

How do I post a XML and get the response status from the response?

I want to post

<myExampleRequest><myValue>xyz</myValue></myExampleRequest>

to http://domain.com/GetStatus.aspx

The page responds with

<myExampleResponse><status>True</status><Message></Message></myExampleResponse>
A: 

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>.

Calvin L
A: 

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).

Jim Ferrans