尝试向 Google WebSub 发送请求时,出现了错误:hub.mode 无效。

huangapple go评论136阅读模式
英文:

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

问题

我正在尝试使用以下代码发布更新到 WeSub,但我遇到错误

> hub.mode 无效

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;
    }
}
英文:

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;
    }

}

答案1

得分: 1

使用 asForm() 在 Laravel 中发送 URL 编码的 POST 请求:

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

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

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

huangapple
  • 本文由 发表于 2023年4月11日 14:37:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983024.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定