We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the problem you're having
A clear and concise description of what the bug is. How can I get the response header in client.go …
Versions
Go version: go version go version go1.12.7 windows/amd64 …
go version
"Show me the code!"
A minimal code snippet can be useful, otherwise we're left guessing! …
// client.go package main import ( "flag" "fmt" "log" "net/http" "net/url" "os" "os/signal" "encoding/json" "github.com/gorilla/websocket" ) var ( addr = flag.String("addr", "127.0.0.1:17505", "http service address") path = flag.String("path", "/ws", "ws path") auth = flag.String("auth", "","auth key") data = flag.String("data", "ping","put data,eg: ping") ) func usage() { fmt.Printf("Usage Example: %s -data 'ping'\n", os.Args[0]) fmt.Printf("Usage Example: %s -data '%s'\n", os.Args[0], `{reqid:"10000",eid:"11111",action:"on",uptime:"1111111"}`) flag.PrintDefaults() } func init(){ flag.Usage = usage } func main() { flag.Parse() log.SetFlags(0) interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) u := url.URL{Scheme: "ws", Host: *addr, Path: *path} log.Printf("connecting to %s", u.String()) h := http.Header{"X-Websocket-Key": []string{*auth} } c, _, err := websocket.DefaultDialer.Dial(u.String(), h) if err != nil { log.Fatal("dial:", err) } defer c.Close() // print request header h2, _ := json.Marshal(h) fmt.Printf("request header: %s\n",h2) done := make(chan struct{}) go func() { defer close(done) for { _, message, err := c.ReadMessage() if err != nil { log.Println("read:", err) return } log.Printf("recv: %s", message) } }() err = c.WriteMessage(websocket.TextMessage, []byte(*data)) if err != nil { log.Println("write:", err) return } fmt.Println("send: ",*data) for { select { case <-done: return case <-interrupt: log.Println("interrupt") err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) if err != nil { log.Println("write close:", err) return } return } } }
The text was updated successfully, but these errors were encountered:
c, resp, err := websocket.DefaultDialer.Dial(u.String(), h) header := resp.Header
Sorry, something went wrong.
Cool, Thank you very much. :-)
Closing as resolved, but let us know if any more questions.
No branches or pull requests
Describe the problem you're having
Versions
"Show me the code!"
The text was updated successfully, but these errors were encountered: