[英]CORS ISSUE using angular4
我正在使用angular 4应用程序。 我正面临CORS问题。
对预检请求的响应未通过访问控制检查:请求的资源上不存在“ Access-Control-Allow-Origin”标头。 因此,不允许访问源' http:// localhost:4200 '。 如果不透明的响应满足您的需求,请将请求的模式设置为“ no-cors”,以在禁用CORS的情况下获取资源。
谁能帮我解决本地和现场问题?
You can use CORS extension in chrome
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
after adding just toggle it and reload the page.
Or you can use xdomain library
Create a proxy.html on your server having below content
<html>
<head>
<script src="xdomain.min.js" data-master="*"></script>
</head>
<body></body>
</html>
// In script src tag give path of your "xdomain.min.js"
And in client side add xdomain.min.js file in your index.html file and add below snippet to index.html file
xdomain.slaves({
"http://serverIp:serverPort": "/contextPathIfAny/proxy.html"
});
这是一个后退问题,您需要在后退响应中将“ Access-Control-Allow-Origin”标头设置为*或将其设置为您的前域。
您无需添加任何Chrome扩展程序。 只需添加下面的代码行即可。 这将解决No'Access-Control-Allow-Origin'标头问题。
@CrossOrigin(origins = "http://localhost:4200")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.