angularjs - 预检响应中的 Access-Control-Allow-Headers 不允许请求 header 字段
angularjs - Request header field is not allowed by Access-Control-Allow-Headers in preflight response
我正在使用库 https://github.com/doedje/jquery.soap/ 将离子应用程序连接到 asmx 网络服务。但是,我收到一个错误:
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.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>
我是不是漏掉了什么?
错误消息似乎表明请求包含一个名为 SOAPAction
.
的 header
因此您似乎需要将 header 名称添加到 web.config
文件的以下部分:
<add name="Access-Control-Allow-Headers"
value="SOAPAction, Content-Type, Authorization" />
我正在使用库 https://github.com/doedje/jquery.soap/ 将离子应用程序连接到 asmx 网络服务。但是,我收到一个错误:
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.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>
我是不是漏掉了什么?
错误消息似乎表明请求包含一个名为 SOAPAction
.
因此您似乎需要将 header 名称添加到 web.config
文件的以下部分:
<add name="Access-Control-Allow-Headers"
value="SOAPAction, Content-Type, Authorization" />