请求标题字段预检响应中的Access-Control-Allow-Headers不允许使用Secret - ASP.NET WEB API

时间:2017-11-03 19:19:05

标签: jquery asp.net asp.net-mvc api

我收到此错误 -

  

请求标题字段预检响应中的Access-Control-Allow-Headers不允许使用Secret。

在asp.net MVC中的我的web api上。

我启用了cors并通过web.config添加了标题。

<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Request-Headers" value="Key,Secret"/>
    <add name="Access-Control-Allow-Origin" value="*" />
  </customHeaders>
</httpProtocol>

现在,当我尝试在jQuery中调用此API(跨域)时,我得到错误。

我的jQuery代码是:

 var url = "http://www.demo.yogihosting.com/mvc/api/API/1"
        $.ajax({
            url: url,
            headers: {
                Key: "Key1",
                Secret: "Secret1"
            },
            dataType: 'json',
            success: function (result, status, xhr) {
                alert(result)
            },
            error: function (xhr, status, error) {
                alert(error)
            }
        });

API网址为Click HERE

API需要标题 - &#39;键&#39; &安培; &#39;秘密&#39;太。 关键值应该是&#39; Key1&#39; 秘密值应该是'Secret1&#39;

API不支持跨域请求。但是在相同的域名请求上它正在发挥作用。

以下是Chrome网络标签中包含请求和响应数据的图片 enter image description here

请帮我弄清楚这里有什么问题?

0 个答案:

没有答案
相关问题