对预检的响应具有无效的HTTP状态代码404,启用CORS后也
问题描述:
我托管了我的webAPI服务。和我的webConfig。对预检的响应具有无效的HTTP状态代码404,启用CORS后也
<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¶ms=[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
请帮我解决这个问题。
答
你可以试试这个Chrome扩展 “允许控制允许原产地”
如果一切都没有为你工作,你可能需要使用IE浏览器,因为一些CORS问题只出现在Chrome上
看看这个https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in织网的API。 –