【发布时间】:2018-06-02 22:36:09
【问题描述】:
我想用 angularjs 从 html 页面调用 API,我已经在 html 页面中编写了这个脚本代码
$http({
method:'POST',
url:'http:192.200.2.2/example.com/api/value',
headers:{
X-EXAMPLE.COM-WEB-APP-API-KEY:"ghdhfghgfhdfdf76878678687567",
X-EXAMPLE.COM-WEB-APP-API-SECRET:"hfghdfghdhfghdf76878678687567",
Content-Type:"application/json"
}
});
我已经在api的web.config中写了,
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering>
<verbs>
<add verb="OPTIONS" allowed="true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
没有标题它调用一个api,但有标题它不调用一个api & 我不能使用任何后端代码
【问题讨论】:
-
请注意,这肯定是服务器问题,而不是客户端问题。请调整您帖子的标签以反映服务器端使用的技术。
-
整个代码在没有标头的情况下工作,但是当标头带有 content-type: application/Json 时,它会给出上述错误
-
标题:{ X-EXAMPLE.COM-WEB-APP-API-KEY:"ghdhfghgfhdfdf76878678687567", X-EXAMPLE.COM-WEB-APP-API-SECRET:"hfghdfghdhfghdf76878678687567", 内容类型: 应用程序/json }