Angular 6-在建立连接之前关闭WebSocket [英] Angular 6 - WebSocket is closed before the connection is established

查看:262
本文介绍了Angular 6-在建立连接之前关闭WebSocket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我启动我的应用程序时,我都会得到这个.我不使用SSL,而是要连接到localhost:4200.

Everytime I start my application I get this. I don't use SSL and I am connecting to localhost:4200.

在建立连接之前关闭WebSocket

WebSocket is closed before the connection is established

是什么原因造成的?

推荐答案

我也遇到了asp.net core和Angular 7.2.0的问题. 正如我刚刚测试的那样,Angular 6.1.10中不存在

I am also getting this problem with asp.net core and Angular 7.2.0. As I just tested it doesn't exist with Angular 6.1.10

在startup.cs中使用时会发生这种情况:

This happens when using in startup.cs:

app.UseSpa(spa => { spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); });

app.UseSpa(spa => { spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); });

当我的asp.net核心在其他端口上运行时.有什么想法如何解决吗? 唯一的解决方法是为我的asp.net网络api添加带有基本URL的带有角度的http拦截器,但是UseProxyToSpaDevelopmentServer绝对是更简单的方法.

When my asp.net core is running on other port. Any ideas how to solve it? The only workaround is to add http interceptor in angular with base url for my asp.net web api, but the UseProxyToSpaDevelopmentServer was definitely easier way.

更好的解决方法是在proxy.conf.json

Even better workaround is to use proxy on angular side with proxy.conf.json https://angular.io/guide/build#proxying-to-a-backend-server

这篇关于Angular 6-在建立连接之前关闭WebSocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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