我如何向我的 Slack Weeb Hook 发送 post 请求

时间:2021-06-20 20:52:31

标签: laravel

我这里有这个代码。基本上我想向我的 weebhook 发出一个 post 请求,但它没有发出成功的请求,它返回 400 作为状态码,我错过了什么

Route::get('/testime',function (){


   $response =  Http::post(env('SLACK_WEBHOOK'),[
        'content' => "Testing testing",
        'embeds' => [
            [
                'title' => "Test ",
                'description' => "URRA",
                'color' => '7506394',
            ]
        ],
    ]);
        return $response->status();
});

1 个答案:

答案 0 :(得分:1)

您收到 400 错误,这是 Slack 告诉您,您的数据丢失或格式错误。要调试,您可以执行以下操作。最有可能说明哪里出了问题。

dd($response->body);

您的结构似乎没有 Slack 支持,这很可能是错误消息。查看示例 here,不确定这是否有效。

$response =  Http::post(env('SLACK_WEBHOOK'), [
    'channel' => 'Your channel id',
    'text' => 'Testing testing',
    'blocks' => [
        [
            'type' => 'header',
            'text' => [
                'type' => 'plain_text',
                'text' => 'URRA',
                'color' => '#36a64f',
            ],
        ],
    ],

]);