phplaravelwebsub

Trying to send a request to Google WebSub by getting error hub.mode invalid


I am trying to post an update to WeSub using the following code but I am getting the error

hub.mode invalid

function sendWebSubNotification($topicUrl) {

    $response = Http::post("https://pubsubhubbub.appspot.com/", [
        'hub.mode' => 'publish',
        'hub.url' => $topicUrl,
    ], [
        'Content-Type' => 'application/x-www-form-urlencoded'
    ]);

    echo $response->getBody();

    if ($response->ok()) {
        // Ping successful
        return true;
    } else {
        // Ping failed
        return false;
    }

}

Solution

  • Use asForm() for sending URL encoded POST requests in Laravel:

    $response = Http::asForm()->post("https://pubsubhubbub.appspot.com/", [
        'hub.mode' => 'publish',
        'hub.url' => $topicUrl,
    ]);