dourun2990 2018-10-18 18:53 采纳率: 100%
浏览 165

打开数据通道的请求不包含令牌

aws ssm start-session returns url and token to open WebSocket Connection. https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_StartSession.html#API_StartSession_ResponseSyntax

Tried a client to open WebSocket connection: https://hashrocket.com/blog/posts/development-of-a-simple-command-line-websocket-client

But I am getting following error when trying to send input like {"type": "echo", "payload": "whoami"}

websocket: close 1003 (unsupported data): Channel : request to open data channel does not contain token.

I tried setting headers with multiple options like

headers := make(http.Header)
headers.Add("Authorization", "Bearer " + token)
headers.Add("token_type", "bearer")
headers.Add("access_token", token)
headers.Add("token", token)
headers.Add("Authentication", token)

//  "github.com/gorilla/websocket"
ws, _, err := websocket.DefaultDialer.Dial(url, headers)

Most of the code is same as in 2nd link mentioned above except trying for wss (not ws).

I guess I am missing something in header. Any idea? Thx

Expected Behavior: Should be able to send requests (like above) and get responses successfully.

  • 写回答

2条回答 默认 最新

  • douyuan9512 2018-10-18 20:27
    关注

    From the godoc for DialContext, which I realize you are just using dial, but it applies. Emphasis mine

    https://godoc.org/github.com/gorilla/websocket#Dialer.DialContext

    If the WebSocket handshake fails, ErrBadHandshake is returned along with a non-nil *http.Response so that callers can handle redirects, authentication, etcetera. The response body may not contain the entire response and does not need to be closed by the application.

    Please try not discarding the response so you can inspect it to determine how to fix the problem.

    As a general rule, if something isn't working out, and you are ignoring some return value, check and see what you are ignoring and you'll often find the solution.

    Let me know if this helps or not and I can update/delete the answer.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?