Angular 5: Http failure response for (unknown url): 0 Unknown Error in EDGE browser when call api [英] Angular 5: Http failure response for (unknown url): 0 Unknown Error in EDGE browser when calling api

查看:31
本文介绍了Angular 5: Http failure response for (unknown url): 0 Unknown Error in EDGE browser when call api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用 .NET Core 2.0 后端 API 的 angular 5 应用程序.从 angular 服务调用 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();
                  });
        });

在配置方法中

app.UseCors("AllowAllOrigins");

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

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

推荐答案

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

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

在 angular 中配置 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

本地主机:3000/api/apiname

localhost:3000/api/apiname

这篇关于Angular 5: Http failure response for (unknown url): 0 Unknown Error in EDGE browser when call api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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