相关疑难解决方法(0)

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

我正在使用 gorilla web socket,我想在本地运行它,我的意思是使用以下 chrome 客户端或其他推荐的工具……当我进入调试模式时,我遇到了错误

我用

"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
}
Run Code Online (Sandbox Code Playgroud)

当我在 chrome 或 web socket 客户端中运行以下 url 时出现错误

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

localhost:8081/mypath
Run Code Online (Sandbox Code Playgroud)

我想运行它

ws://localhost:8081/mypath
Run Code Online (Sandbox Code Playgroud)

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

为了检查它,我使用了 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-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

go websocket

4
推荐指数
1
解决办法
1735
查看次数

标签 统计

go ×1

websocket ×1