我的客户端 laravel-echo 没有在标头中发送 cookie 参数,braodcasting/auth 需要标头中的 cookie 来授权 websocket 连接,当我尝试使用 fetch 发送相同的请求时,它可以工作,但当涉及我的 laravel echo 时却不行,怎么办我在标头中发送 cookie 参数 我尝试了一些技巧,但没有成功。
window.Echo = new Echo({
broadcaster: 'reverb',
wsHost: 'localhost',
key: 'yn0yitpyoptuuqiyjrhm',
wsPort: 8080,
wssPort: 8080,
forceTLS: false,
authEndpoint: 'http://localhost:8000/broadcasting/auth',
headers: {
Authorization: `Bearer ${token}`,
Cookie: cookies,
},
withCredentials: true,
enabledTransports: ['ws', 'wss'],
});
可能有任何可能的原因。请检查并配置以下内容。
*config/broadcasting.php*
& *config/app.php*
.*config/broadcasting.php*
& .env
文件中配置。routes/channel.php
文件包含所需的通道路由
用于操作。