HTTP headers in Websockets client API

后端 未结 11 2383
情话喂你
情话喂你 2020-11-22 10:41

Looks like it\'s easy to add custom HTTP headers to your websocket client with any HTTP header client which supports this, but I can\'t find how to do it with the JSON API.

11条回答
  •  庸人自扰
    2020-11-22 10:59

    My case:

    • I want to connect to a production WS server a www.mycompany.com/api/ws...
    • using real credentials (a session cookie)...
    • from a local page (localhost:8000).

    Setting document.cookie = "sessionid=foobar;path=/" won't help as domains don't match.

    The solution:

    Add 127.0.0.1 wsdev.company.com to /etc/hosts.

    This way your browser will use cookies from mycompany.com when connecting to www.mycompany.com/api/ws as you are connecting from a valid subdomain wsdev.company.com.

提交回复
热议问题