Pusher auth 端点响应 html,如何解决这个问题?

Pusher auth endpoint responded with html, how to fix this?

我目前正在使用 laravel 5.8 和 pusher 3.0.3,我是这些新技术的新手。我创建了一个简单的聊天室,但无法使用 pusher 收听状态频道。我之前尝试过 Echo 但我找不到调试它的方法。

这是来自控制台的pusher:subscription_error

Pusher: JSON returned from webapp was invalid, yet status code was 200. Data was: <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

我已经将此行添加到我的 BroadcastServiceProvider.php

Broadcast::routes(['middleware' => ['auth:api']]);
require base_path('routes/channels.php');

我已经通过 public 通道从推送调试器接收到事件,所以我认为我已经正确设置了我的凭据。

这是我的 bootstrap.js 的底部部分。

const CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');

var pusher = new Pusher('61540f91921896045e25', {
    cluster: "ap1",
    forceTLS: true,
    //authEndpoint: 'authchatuser'
    authEndpoint: '/broadcasting/auth',
    auth: {
      headers: {
        'X-CSRF-Token': CSRF_TOKEN
      }
    }
});

var channel = pusher.subscribe('presence-chatroom');

//var channel = pusher.subscribe('chatroom');
channel.bind('MessagePosted', function(data) {
   console.loga(data);
});

channel.bind('pusher:subscription_error', function(data) {
   console.log("Pusher: " + data);
});

在网络选项卡中,我看不到对我的推送器 authEndpoint broadcasting/auth 的请求,但我看到对我的主页的 GET 请求,我认为它以 200 响应是我收到 html 而不是 json.

的原因

请帮我解决这个问题,或者您是否有想法绕过端点并发送 json 数据进行身份验证(推送器期望的正确数据)而不是从我的 web.php?谢谢。

您不需要绕过端点,而是应该将端点修改为 return 正确的数据。 您的身份验证端点应该 return 一个 JSON 正文以及一个 HTTP 代码。 The documentation 状态:

Successful responses from an authentication endpoint should carry a 200 OK HTTP status and a body of the form
{ "auth": $AUTHORIZATION_STRING }

这与您收到的错误一致,表明预期 JSON 但收到 HTML。