把头发拉了几个小时。我正在学习Angular并尝试编写一个在家庭自动化服务器(Indigo)中使用API的应用程序。每当我尝试调用其中一个RESTAPi时,我都会得到这个:
HTML1300: Navigation occurred.
File: index.html
Main Controller Startup...
SEC7118: XMLHttpRequest for http://192.168.168.157:8176/devices// required Cross Origin Resource Sharing (CORS).
File: index.html
SEC7120: Origin http://localhost:50441 not found in Access-Control-Allow-Origin header.
File: index.html
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
File: index.html
Error: ; 0
http://192.168.168.157:8176/devices/ is the server (on a Mac on my local network)
http://localhost:50441 is the web server that Visual Studio uses during debugging
我已添加到我的web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
有没有人知道我需要做些什么才能让它发挥作用?
由于
标记
答案 0 :(得分:0)
所以,我得到了它的工作。
原来它与本地asp.net服务器无关。我尝试连接的服务器是用CherrPy编写的。我所要做的只是添加
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
显然,一旦我完成测试,我会进一步限制它。
问候
标记