I'm trying to send xml with POST
method in javascript using the XmlHttpRequest
object.
On my server I've a web service which receives SOAP request.
When I want to send xml, the browser previusly try to send a preflight OPTIONS
request to the server, but it returns OPTIONS 405 Method Not Allowed
.
The problem is that I've in my response header the Access-Control-Method-Allowed : POST,OPTIONS,GET,PUT
so I guess my server accepts OPTIONS method, but my web service only understands POST
request.
Here's some code :
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', url, false);
var sr = mySoapRequest; //Here's my XML
xmlhttp.onreadystatechange = () => {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var xml = xmlhttp.responseXML;
console.log(xml);
this.showAlert(xml);
}
}
}
xmlhttp.setRequestHeader("content-type", "file/xml");
xmlhttp.send(sr);
Here's my HTTP protocol request headers :
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:fr-FR,fr;q=0.8,en;q=0.6,en-US;q=0.4
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
DNT:1
Host:192.168.149.127
Origin:http://192.168.149.1:8100
Referer:http://192.168.149.1:8100/?ionicplatform=android
Here's my HTTP protocol response headers :
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:accept, authorization, content-type, x-requested-with
Access-Control-Allow-Methods:GET, POST, OPTIONS, PUT
Access-Control-Allow-Origin:*
Access-Control-Max-Age:1
Connection:keep-alive
Content-Length:224
Content-Type:text/xml;charset=UTF-8
Date:Thu, 16 Feb 2017 10:25:33 GMT
Server:WildFly/8
X-Content-Type-Options:nosniff
X-FRAME-OPTIONS:SAMEORIGIN
X-Powered-By:Undertow/1
X-XSS-Protection:1
Any suggestions ?