【问题标题】:Response for preflight has invalid HTTP status code 404, After CORS enabled also预检响应具有无效的 HTTP 状态代码 404,在启用 CORS 后也
【发布时间】:2017-06-28 17:58:57
【问题描述】:

我已经托管了我的 webAPI 服务。和我的 webConfig。

<httpProtocol>
     <customHeaders>
         <add name="Access-Control-Allow-Origin" value="*" />
          <add name="Access-Control-Allow-Headers" value="*" />
          <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
     </customHeaders>
   </httpProtocol>

但是,当我访问此服务时。

1.  General 
1.  Request URL: http://localhost:62007/api/Orders/?$select=OrderID,EmployeeID,CustomerID&params=[object%20Object]
2.  Request Method: OPTIONS
3.  Status Code: 400 Bad Request
4.  Remote Address: [::1]:62007

2.  Response Headers
1.  Access-Control-Allow-Headers:*
2.  Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
3.  Access-Control-Allow-Origin:*
4.  Cache-Control:no-cache
5.  Content-Length:98
6.  Content-Type:application/json; charset=utf-8
7.  Date:Fri, 10 Feb 2017 11:22:33 GMT
8.  Expires:-1
9.  Pragma:no-cache
10. Server:Microsoft-IIS/10.0
11. X-AspNet-Version:4.0.30319
12. X-Powered-By:ASP.NET
13. X-SourceFiles:=?UTF-8?B?RDpcU2FtcGxlXE1WQ1xHcmlkV2ViQXBpXEdyaWRXZWJBcGlcYXBpXE9yZGVyc1w=?=

3.  Request Headers
1.  Accept:*/*
2.  Accept-Encoding:gzip, deflate, sdch, br
3.  Accept-Language:en-US,en;q=0.8
4.  Access-Control-Request-Headers:dataserviceversion, maxdataserviceversion
5.  Access-Control-Request-Method:GET
6.  Connection:keep-alive
7.  Host:localhost:62007
8.  Origin:http://jsplayground.syncfusion.com
9.  Referer:http://jsplayground.syncfusion.com/wqtmoa3v
10. User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

当我从http://jsplayground.syncfusion.com 访问资源时,出现以下错误

加载资源失败:服务器响应状态为 400 (错误请求)VM2343 djbei0ge:1 XMLHttpRequest 无法加载 http://localhost:62007/api/Orders/?$select=OrderID,EmployeeID,CustomerID&params=[object%20Object]。 预检响应包含无效的 HTTP 状态代码 400

请帮我解决这个问题。

【问题讨论】:

标签: asp.net web-services asp.net-web-api


【解决方案1】:

你可以试试这个 chrome 扩展 "Allow-Control-Allow-Origin"

这个页面也可能有帮助 https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api#enable-cors

如果一切都不适合你,你可能想使用 IE,因为一些 CORS 问题只在 chrome 上出现

【讨论】:

    猜你喜欢
    • 2017-09-26
    • 2018-04-25
    • 2018-07-01
    • 2016-07-15
    • 2016-01-22
    • 1970-01-01
    • 2018-09-30
    • 2017-12-22
    • 2018-03-12
    相关资源
    最近更新 更多