我正在使用javascript代码调用部署在weblogic上的soap webservice,并使用jaxws在java中开发。从IE11我正在从SOAP响应,但由镀铬我得到以下错误:CORS不能在Angular 2中使用chrome
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:4200' is therefore not allowed access.
The response had HTTP status code 405.
我已经加入CORS延伸的镀铬,然后我得到了以下新的错误:
Response for preflight has invalid HTTP status code 405
我还设置请求头像如下:
xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader('Access-Control-Allow-Headers', 'X-Custom-Header');
xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,PUT,DELETE');
但仍然没有成功。
下面是我的代码片段调用部署在WebLogic
var soapMessage = this.createSOAPMessage();
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else {
xhr = null;
}
return xhr;
}
var xhr = createCORSRequest('POST','http://IPAddress:7001/Path/ServiceImplService?WSDL');
if(!xhr){
console.log('XHR Issue');
return;
}
xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader('Access-Control-Allow-Headers', 'X-Custom-Header');
xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,PUT,DELETE');
xhr.send(soapMessage);
var result
xhr.onload = function(){
result = xhr.responseText;
console.log('===Result====> '+result);
}
return result;
'我还设置请求头如下:' - 你不发送这些头文件,这些**必须**接收CORS ... CORS由服务器控制,客户端无法告诉服务器**无论您的设置如何,都可以给我您的资源**:p –
你的意思是我必须在服务器端处理cors请求,而不是从我们的javascript? – Nitin
这就是CORS从 –