我正在使用lib https://github.com/doedje/jquery.soap/将离子应用程序连接到asmx Web服务。然而,我发现了一个错误:angularjs - 预操作响应中的Access-Control-Allow-Headers不允许请求标头字段
XMLHttpRequest cannot load http://10.10.9.169/UserService3/WebService1.asmxgetUserbyUsername . Request header field SOAPAction is not allowed by Access-Control-Allow-Headers in preflight response. jquery.soap.js:456 Uncaught Error: Unexpected Content: undefined
这里是我的controller.js
代码:
$scope.enterlogin = function(usern,pass)
{
$.soap({
url: 'http://<webservice's ip address>/UserService3/WebService1.asmx',
method: 'getUserbyUsername',
data: {
uname: usern,
passw: pass
},
success: function (soapResponse) {
console.log('response is = ' + soapResponse);
},
error: function (soapResponse) {
// show error
console.log('response error is = ' + soapResponse);
}
});
}
我还添加在web服务的web.config
文件中的以下内容:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpHandlers>
<add verb="GET,HEAD,POST,OPTIONS" path="*.asmx" type="System.Web.UI.WebServiceHandlerFactory" />
</httpHandlers>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Authorization" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
上午我遗漏了什么?