我在web.Server元素中配置了Web.Config。
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:xxxxx" />
<add name="Access-Control-Allow-Headers" value="content-type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" />
</customHeaders>
</httpProtocol>
来到GET请求检索所有数据。
当我想在请求中POST新元素时,我得不到错误405方法。 可能是什么原因?
请求示例: 一般:
Request URL:http://localhost:xxxxx/api/company
Request Method:OPTIONS
Status Code:405 Method Not Allowed
响应标题:
Access-Control-Allow-Headers:content-type
Access-Control-Allow-Methods:GET, POST, OPTIONS, PUT, DELETE
Access-Control-Allow-Origin:http://localhost:yyyyy
Allow:GET,POST
Cache-Control:no-cache
Content-Length:76
Content-Type:application/json; charset=utf-8
请求标题:
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:localhost:xxxxx
Origin:http://localhost:yyyyy
Referer:http://localhost:yyyyy/ddddd/zzzzzz
答案 0 :(得分:0)
我相信Access-Control-Allow-Origin应该是“*”。然后它可能会工作。