【发布时间】:2014-11-26 18:50:17
【问题描述】:
在我不得不 POST 数据之前,对我的 API 的请求一直在进行。 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
【问题讨论】:
-
也许我看错了,但这并不是说您的请求方法是 OPTIONS 而不是 POST
-
是的,响应说只允许 POST 和 PUT。
-
是的,这就是预检请求。因为它是一个 CORS 请求,所以它询问 POST 是否是一种可接受的方法。但是你可能正在做一些事情......
标签: asp.net asp.net-mvc asp.net-mvc-4 http