我在前端有Ajax调用,我通过ajax调用调用WCF服务,但是ajax调用有一些添加标题,这就是为什么第一次预检OPTIONS请求被提升而且由于“url”已经被cors策略阻止而导致其下降。我在我的web.config文件中添加了下面的代码,但它仍在工作。<system.webServer> <security> <requestFiltering> <verbs> <add verb="OPTIONS" allowed="true" /> <add verb="POST" allowed="true" /> <add verb="GET" allowed="true" /> <add verb="DELETE" allowed="false" /> </verbs> </requestFiltering> </security> <httpProtocol> <customHeaders> <remove name="X-Powered-By" /> <add name="Access-Control-Allow-Credentials" value="true" /> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Methods" value="GET,POST,DELETE,OPTIONS" /> <add name="Access-Control-Allow-Headers" value="accept, cache-control, content-type, authorization, context" /> </customHeaders> </httpProtocol> </system.webServer>$.ajax({ async: true, type: "POST", headers: { 'Authorization': 'Basic ' + btoa(BasicAuth), 'Context': 'Context' + btoa(ContextHeader) }, contentType: "application/json; charset=utf-8", data: '{"Id": "' + Id + '" }', url: URL + "/MethodName", success: function (result) { response = result; if (response == true) Xrm.Page.data.refresh(true); $('#msgDiv').fadeOut('slow'); },上面的代码我写的是javascript。在HTTP调用它工作正常。但在HTTPS调用它不工作。我在控制台上收到如下错误enter code here选项https:// abc / xyz 400(错误请求)来自' https:// abc / xyz from origin'Kyps:// Localhost '的XMLHttpRequest访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:它没有HTTP ok状态
添加回答
举报
0/150
提交
取消