跳转到内容
搜索文档

通过 HTTP 发布到 Queue

直接通过 HTTP 发布到 Queue。

最后更新 查看 MarkdownAgent 设置

以下示例展示如何使用 Cloudflare API 令牌进行身份验证,从任何 HTTP 客户端向 Queue 发布消息。

这使您可以从任何支持 HTTP 的服务或编程语言(包括 Go、Rust、Python 甚至 Bash 脚本)写入 Queue。

前提条件

1. 发送测试消息

要确认身份验证成功并将消息写入队列,请在命令行使用 curl

# Make sure to replace the placeholder with your shared secret
curl -XPOST -H "Authorization: Bearer <paste-your-api-token-here>" "https://api.cloudflare.com/client/v4/accounts/<paste-your-account-id-here>/queues/<paste-your-queue-id-here>/messages" --data '{ "body": { "greeting": "hello" } }'
{"success":true}

这将发出 HTTP POST 请求,若成功,将返回 HTTP 200 及 success: true 响应正文。

  • 若收到 HTTP 403,表示 API 令牌无效或没有 Queues Edit 权限。

有关 HTTP Push API 的完整文档,请参阅 Cloudflare API 文档

这篇文档对您有帮助吗?