我使用angular $ http.get模块从api系统获取GET但是:
api端点系统只接受GET方法并且不能使用OPTION方法
REQUEST标题:
Host: www.example.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Access-Control-Request-Method: GET
Access-Control-Request-Headers: x-device-type,x-software-version,x-unit-measurement
Origin: http://localhost:3000
Connection: keep-alive
RESPONSE标题:
状态代码: 405方法不允许
Access-Control-Allow-Headers: Content-Type, Accept, origin, referring-domain, X-UNIT-MEASUREMENT, X-AUTH-TOKEN, X-DEVICE-TYPE, X-SOFTWARE-VERSION
Access-Control-Request-Method: GET, POST, PUT, DELETE, OPTIONS
Allow: GET
Cache-Control: private,no-transform
Content-Length: 1565
Content-Type: text/html; charset=UTF-8
Date: Thu, 14 Apr 2016 11:41:13 GMT
Server: Microsoft-IIS/8.5
X-API-VERSION: 1.40.1.0
X-INSTANCE-ID: ALL
X-Powered-By: ASP.NET
access-control-allow-credentials: true
access-control-allow-origin: *
p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
我刚试过这件事:
1:设置默认内容类型甚至是text / plain和其他类型 [Not Working]
$httpProvider.defaults.headers.common['Content-Type'] ='application/x-www-form-urlencoded; charset=UTF-8';
答案 0 :(得分:0)
因为我使用Atom Electron shell来运行我的应用程序,所以我的快速解决方案是使用--disable-web-security
来禁用浏览器中的CORS保护。