2017-04-07 99 views
2

我正在使用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> 

上午我遗漏了什么?

回答

0

错误消息似乎表明请求包含名称为SOAPAction的标头。

所以好像你需要的是标题名称添加到您的web.config文件的以下部分:

<add name="Access-Control-Allow-Headers" 
    value="SOAPAction, Content-Type, Authorization" /> 
相关问题