ActionCable(Rails5) and Android client

别来无恙 提交于 2020-01-05 06:06:40

问题


I'm using as backend framework Ruby on Rails 5, actually action cable for websocket connection and as front end Android. I create server as said in https://github.com/rails/actioncable-examples and for client connection use library https://github.com/hosopy/actioncable-client-java. When I'm connecting to the server it every time fails with exception:

Started GET "/cable" for 192.168.0.106 at 2017-06-15 17:57:19 +0500
Cannot render console from 192.168.0.106! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Started GET "/cable/" [WebSocket] for 192.168.0.106 at 2017-06-15 17:57:19 +0500
Request origin not allowed: 
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for 192.168.0.106 at 2017-06-15 17:57:19 +0500

What is problem, what i'm doing wrong?


回答1:


I had the same issue. After reading some stuff I found "Request origin not allowed: " comes due to forgery protection module of action cable. Simple solution is to add this line to your config/environments/yourEnvironment.rb:

config.action_cable.disable_request_forgery_protection = true

Hope that Helps!!!



来源:https://stackoverflow.com/questions/44568520/actioncablerails5-and-android-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!