来自 CORS 预检通道的 CORS 头 'Access-Control-Allow-Headers' 的令牌 'appkey' 无效)。

1、服务端:

web.config文件中:

<system.webServer>
  
     <httpProtocol>
      <customHeaders> 
       <add name="Access-Control-Allow-Origin" value="http://nmcs.lemon95.com:8089" /> 
       <add name="Access-Control-Allow-Credentials" value="true" /> 
       <add name="Access-Control-Allow-Headers" value="SecretKey,AppKey,UniqueKey" /> 
      customHeaders>
    httpProtocol>
system.webServer>

ps:

Access-Control-Allow-Origin:只能配置一个域名,不能配置多个域名,不能为"*"
Access-Control-Allow-Headers:加入需要传入参数名
 

2、客服端ajax异步调用

<script src="js/jquery-1.8.2.js">script>
    
    <script>

        function test()
        {
            var url = "http://xxxx/Stats"; //api地址
            
            $.ajax({
                type: "get",
                url: url,
                data: null,
                dataType: "json",
                cache: false,
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                headers:
                {
                    SecretKey: "ec8b570ad4bd403783c52ecb5cdfa849",
                    AppKey: "1259402909",
                    UniqueKey:"987654321"
                },
                beforeSend: function ()
                {
                    
                },           
                success: function (data)
                {
                    alert(data);
                },
                complete: function (XMLHttpRequest, textStatus) {
                   
                },
                error: function (errorData) {
                    alert(errorData);
                }
            });
        }
    script>

 

转载于:https://www.cnblogs.com/zoro-zero/p/6077659.html

你可能感兴趣的:(来自 CORS 预检通道的 CORS 头 'Access-Control-Allow-Headers' 的令牌 'appkey' 无效)。)