douqi2804
2017-12-04 14:38
浏览 1.2k
已采纳

在本地运行Web-Socket进行调试

I’m using gorilla web socket and I want to run it locally , I mean with the following chrome client or other recommended tool …when I run into debug mode I got error

I use

"github.com/gorilla/websocket"


var upgrader = websocket.Upgrader{
    ReadBufferSize:  1024,
    WriteBufferSize: 1024,
}

upgrader.CheckOrigin = func(r *http.Request) bool { return true }

c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
    log.Print("upgrade:", err)
    return
}

When I run the following url in chrome or web socket client I got error

websocket: not a websocket handshake: 'upgrade' token not found in 'Connection' header

localhost:8081/mypath

and I want to run it

ws://localhost:8081/mypath

and provide token for local simulation, how I can do it ?

To check it I use Simple WebSocket Client of chrome. any other client will be helpful

EDIT:

when I try it in the chrome console I got the following error:

VM42:164 Refused to connect to 'ws://localhost:8081/mypath' because it violates the following Content Security Policy directive: "connect-src 'self' uploads.github.com status.github.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss://live.github.com

图片转代码服务由CSDN问答提供 功能建议

我正在使用大猩猩Web套接字,并且想在本地运行,我的意思是使用以下chrome客户端 or 其他推荐工具…当我进入调试模式时,出现错误

我使用

 “ github.com/gorilla/websocket” \  n 
 
var upgrader = websocket.Upgrader {
 ReadBufferSize:1024,
 WriteBufferSize:1024,
} 
 
upgrader.CheckOrigin = func(r * http.Request)bool {返回true} 
 
c  ,err:= upgrader.Upgrade(w,r,nil)
if err!= nil {
 log.Print(“ upgrade:”,err)
 return 
} 
    
 
 

当我在chrome或Web套接字客户端中运行以下网址时,出现错误

websocket:不是websocket握手:在“连接”中找不到“升级”令牌 标头

  localhost:8081 / mypath 
   
 
 

,我想运行它 \ n

  ws:// localhost:8081 / mypath 
   
 
 

并提供用于本地模拟的令牌,我该怎么做?

要进行检查,我使用chrome的Simple WebSocket Client。

编辑

在Chrome控制台中尝试时,出现以下错误 :

VM42:164拒绝连接到'ws:// localhost:8081 / mypath',因为它违反了以下内容安全策略指令:“ connect- src 'self'uploads.github.com status.github.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production- 仓库文件5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss ://live.github.com

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新