我尝试发送GET时遇到了javaScript问题。使用xmlhttprequest
我无法访问Web服务,但我可以使用Soap UI访问它。
IE11模式调试中的错误代码是:
SCRIPT5022:InvalidAccessError
代码如下:
var xmlToSend = "<?xml version='1.0' encoding='utf-8'?>";
xmlToSend += "<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:ws='some xmlns'>";
xmlToSend += "<soap:Header/> ";
xmlToSend += "<soap:Body>";
xmlToSend += "<ws:searchMultisPolicy>";
xmlToSend += "<ws:xmlRequest>";
xmlToSend += "<![CDATA[";
xmlToSend += "<searchMultisPolicyReq>";
xmlToSend += "<wsHeader>";
xmlToSend += "<user>B12345674280010001</user>";
xmlToSend += "<logginDate>27/04/2015</logginDate>";
xmlToSend += "<roles>170</roles>";
xmlToSend += "</wsHeader>";
xmlToSend += "<params>";
xmlToSend += "<idProveedor>02</idProveedor>";
xmlToSend += "<nifTomador>12341234D</nifTomador>";
xmlToSend += "<fechaOcurrencia>2015-04-27T10:00:00</fechaOcurrencia>";
xmlToSend += "<poliza>80208813</poliza>";
xmlToSend += "<razonSocial></razonSocial>";
xmlToSend += "</params>";
xmlToSend += "</searchMultisPolicyReq>";
xmlToSend += "]]>";
xmlToSend += "</ws:xmlRequest>";
xmlToSend += "</ws:searchMultisPolicy>";
xmlToSend += "</soap:Body>";
xmlToSend += "</soap:Envelope>";
var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.loadXML(xmlToSend);
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = state_Change;
xmlhttp.open(
"POST",
"some WebService",
0, "user", "pwd");
xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
xmlhttp.setRequestHeader("action", "urn:searchMultisPolicy");
xmlhttp.setRequestHeader("Content-Type", "application/soap+xml");
xmlhttp.setRequestHeader("charset", "UTF-8");
xmlhttp.setRequestHeader("Accept-Encoding", "application/soap+xml");
xmlhttp.send(xmldoc);
function state_Change() {
if (xmlhttp.readyState == 4) {
// if "OK"
if (xmlhttp.status == 200) {
alert("OK");
var objResponse = document.getElementById("responseDiv");
objResponse.innerText = xmlhttp.responseXML.xml;
} else {
alert("Problema recibiendo XML"+" "+xmlhttp.status);
}
}
}
答案 0 :(得分:0)
Access-Control-Allow-Origin是一个响应标头,而不是请求标头。
您必须配置要发出请求的系统,以允许您发出跨域请求。