【发布时间】:2017-07-05 10:03:06
【问题描述】:
我正在尝试使用XmlHttpRequest 对象在javascript 中使用POST 方法发送xml。
在我的服务器上,我有一个接收 SOAP 请求的网络服务。
当我想发送 xml 时,浏览器之前尝试向服务器发送预检 OPTIONS 请求,但它返回 OPTIONS 405 Method Not Allowed。
问题是我的响应标头中有 Access-Control-Method-Allowed : POST,OPTIONS,GET,PUT,所以我猜我的服务器接受 OPTIONS 方法,但我的网络服务只理解 POST 请求。
这里有一些代码:
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);
这是我的 HTTP 协议请求标头:
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
这是我的 HTTP 协议响应标头:
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
有什么建议吗?
【问题讨论】:
标签: javascript soap xmlhttprequest cors wildfly