简体   繁体   English

Angular套接字因400错误请求而失败

[英]Angular socket fails with 400 bad request

Its an angular app (angular 1.X) that tries to connect to node-app. 它是一个尝试连接到节点应用程序的角度应用程序(角度为1.X)。 It hasn't been easy to set up (primarly the frontend) so I ended up with having this on frontend (in bower.json): 设置起来并不容易(主要是前端),所以我最终将其放在前端(在bower.json中):

"socket.io-client": "^0.7.10",
"angular-socket-io": "^0.7.0"

and this on backend (in package.json): 这在后端(在package.json中):

"socket.io": "^1.7.3",

So client has version less than 1.X while server has version bigger than 1.X. 因此,客户端的版本小于1.X,而服务器的版本大于1.X。

When I try to connect I get 当我尝试连接时,我得到

Bad request (HTTP 400) 

while trying to go to 试图去

http://localhost/socket.io/1/

I only entered this in my socketFactory on frontend: 我只在前端的socketFactory中输入了此代码:

io.connect('http://localhost/', {'transports': ['websocket', 'polling']});

I guess the problem is the different versions on front and back? 我想问题是正面和背面的版本不同? Must they be exactly the same or it is enough being both 0.X och 1.X? 它们必须完全相同还是都为0.X和1.X足够? Moreover, isn't there a workaround? 此外,没有解决方法吗? Im quite sure that upgrading frontend to 1.X will cause other problems (that were lost when I downgraded to less than 1.X) 我非常确定将前端升级到1.X会引起其他问题(当我降级到1.X以下版本时就丢失了)

When you're trying to go to http://localhost/socket.io/1/ you're doing HTTP method GET request. 当您尝试转到http://localhost/socket.io/1/时,您正在执行HTTP方法GET请求。 It's different than connection via sockets. 它与通过套接字的连接不同。 So it's normal that it returns bad request response when you opening http://localhost/socket.io/1/ in browser. 因此,在浏览器中打开http://localhost/socket.io/1/时,返回错误的请求响应是正常的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM