我的API的请求一直在流动,直到我不得不POST数据。 API期待JSON所以我将content-type
更改为application/json
,这导致所有CORS实现都需要preflights,现在我得到405.事情是,请求/响应看起来不错。请求标头接受,内容类型位于Access-Control-Request-Headers
。允许请求方法POST
,POST
和PUT
。 Access-Control-Allow-Origin允许所有来源。是什么给了什么?
Remote Address: -
Request URL: -
Request Method: OPTIONS
Status Code: 405 Method Not Allowed
Request Headers
Accept: */*
*/// for the sake of syntax highlighting
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Access-Control-Request-Headers: accept, content-type
Access-Control-Request-Method: POST
Cache-Control: no-cache
Connection: keep-alive
Host: -
Origin: http://localhost
Pragma: no-cache
Referer: http://localhost/
Response Headers
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Origin: *
Allow: POST,PUT
Cache-Control: no-cache
Content-Length: 76
Content-Type: application/json; charset=utf-8
Date: Wed, 01 Oct 2014 19:43:56 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
答案 0 :(得分:1)
相关的StackOverflow帖子
这些帖子(1,2)对enable CORS on WebApi using Microsoft.AspNet.WebApi.Cors package说,并提供implementation of WebApiConfig.cs。
这些帖子(1,2,3)表示要在<system.webServer>
内添加此内容来删除WebDAV。
<handlers>
<remove name="WebDAV"/>
</handlers>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
</modules>
答案 1 :(得分:1)
services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));