角5 :(未知URL)的Http故障响应:0调用API时,EDGE浏览器中出现未知错误 [英] Angular 5: Http failure response for (unknown url): 0 Unknown Error in EDGE browser when calling api

查看:299
本文介绍了角5 :(未知URL)的Http故障响应:0调用API时,EDGE浏览器中出现未知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个angular 5应用程序,它调用.NET Core 2.0后端api.从角度服务对API的调用在所有浏览器(Chrome,Firefox,IE11)中都可以正常运行,但在EDGE中却不行.在EDGE中,我遇到了错误

I have a angular 5 application which calls a .NET Core 2.0 backend api. Call to the API from the angular service works fine in all browsers (Chrome, Firefox, IE11) but not in EDGE. In EDGE, i am getting the error

Http failure response for (unknown url): 0 Unknown Error.

这是一个CROSS ORIGIN CALL,并且在API中启用了Cors,如下所示.现在,我可以启用任何来源

It is a CROSS ORIGIN CALL and Cors has been enabled in the API as below. Right now i am enabling for any origin

 services.AddCors(options =>
        {
            options.AddPolicy("AllowAllOrigins",
                  builder =>
                  {
                      builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
                  });
        });

然后在Configure方法中

And in Configure method

app.UseCors("AllowAllOrigins");

它适用于Edge以外的所有浏览器.感谢您的帮助.

It works for all browsers except Edge. Appreciate your help.

推荐答案

(未知url)的HTTP失败响应:0未知错误.

Http failure response for (unknown url): 0 Unknown Error.

发生此错误是由于与其他浏览器相比,Edge具有更高的安全性. 这确实是Cors问题.

This error occure due to edge have advanced security as compared to other browser. this is actully Cors issue .

可以通过两种方式解决->

that can be solved in two way->

您可以通过添加为Access-Control-Allow-Origin:*或

either you can modify header in server side by adding as Access-Control-Allow-Origin:* or

在角度内配置proxy.conf.json,确保在配置代理时不会在浏览器控制台中显示实际的服务器URL,

configure the proxy.conf.json inside the angular make sure when you configured the proxy then its won't show the actual server url in broswer console,

例如,您的客户端url为localhost:3000,服务器url的api托管为www.server.com/api/apiname,然后在浏览器控制台中将显示如下

for example , your client url as localhost:3000 and server url where api hosted as www.server.com/api/apiname then in browser console it will show like below

localhost:3000/api/apiname

localhost:3000/api/apiname

这篇关于角5 :(未知URL)的Http故障响应:0调用API时,EDGE浏览器中出现未知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆