Goal: To send XML using XmlHttpRequest as text/xml via POST to PHP file. PHP file then does magic and saves to an XML on the server. A component on an HTML page will be updated with data from the XML.
Problem: I saw success with this when testing with the php web server, which I initiated in command line with php -S 127.0.0.1:8000
but when tested on a Microsoft-IIS server, I got a "405 Method Not Allowed" response. When tested on an Apache server, I get a "200 OK" response, but server XML file is unchanged.
The Javascript code that sends the XML to PHP is something like this:
var xHttp;
if (window.XMLHttpRequest) {
xHttp = new XMLHttpRequest();
} else {
xHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xHttp.onreadystatechange = function() {
if (xHttp.readyState == 4 && xHttp.status == 200) {
update();
}
}
xHttp.open("POST", appLocation, true);
xHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xHttp.setRequestHeader("Content-Type", "text/xml");
xHttp.send(xmlDoc);
In the above code, xmlDoc is the XML I want to send and appLocation is the location on the server where the PHP file is. update() is a function I wrote to update a component on an HTML page with data from the XML file that is saved by PHP. From this, I would know that the XML has successfully changed.
The PHP looks like:
$xml = file_get_contents("php://input");
$xmlDoc = simplexml_load_string($xml);
// Magic ***
$xmlDoc -> asXml("some-file-on-server.xml");
If I can be successful on either one Apache or Microsoft servers, I would be content. Thanks in advance! Hopefully this is detailed enough. I found a number of duplicates but nothing that quite helped me solve my problem.