预检的响应具有无效的HTTP状态代码404,也启用了CORS

时间:2017-02-10 11:39:09

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

我托管了我的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/ $选择=订单ID,雇员ID,客户ID&安培; PARAMS = [对象%20Object]。   预检的响应具有无效的HTTP状态代码400

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用此Chrome扩展程序 “允许 - 控制 - 允许来源”

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

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