1

我正在尝试使用 Google Cloud Tasks,通过“试用此 API”网络功能或 Ruby Google Cloud SDK 创建任务。

我无法将有效负载交付给工作人员。

  1. 将 Http 方法作为 POST 发送实际上有效,但在 Cloud Tasks UI 中显示为 GET。

  2. 没有负载或标头发送到工作人员或显示在 Cloud Task UI 中。我尝试过 Base64、JSON、普通字符串。(见下图)

例子:

要求:

{
  "task": {
    "httpRequest": {
      "httpMethod": "POST",
      "body": "SGVsbG8=",
      "url": "https://some-random-url"
    }
  }
}

回复:

{
  "name": "projects/<my-project>/locations/europe-west1/queues/default/tasks/73572672049866200001",
  "scheduleTime": "2019-07-03T14:49:34.450453Z",
  "createTime": "2019-07-03T14:49:34Z",
  "view": "BASIC",
  "httpRequest": {
    "url": "https://some-random-url/",
    "httpMethod": "POST",
    "headers": {
      "User-Agent": "Google-Cloud-Tasks"
    }
  },
  "dispatchDeadline": "600s"
}

示例 Ruby 代码:

task = {
          http_request: {
            url: <project/location/queue/url>,
            http_method: 'POST',
            body: "Something"
          }
        }

        response = @client.create_task(@parent, task)

谷歌云用户界面截图:

空标题

空有效载荷

是否有一些特殊的格式来设置通过 POST 传递的有效负载?

谢谢!

4

1 回答 1

0

感谢您的这篇文章,这是现有 Cloud Tasks UI 中的一个错误,我们正在修复这个错误。

同时,可以通过运行以下命令来确定任务的正确 HTTP 方法:

gcloud beta 任务描述

https://cloud.google.com/sdk/gcloud/reference/beta/tasks/describe

上述命令将显示该任务的正确 HTTP 方法。

来自:Google Cloud Tasks 在使用 HttpRequest 作为 payload_type 时始终将 HttpMethod 设置为 GET

您还可以使用 get task 方法获取更多信息。

于 2019-07-08T17:01:13.087 回答