问题
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