无法在 Google 云任务上设置 Payload/Body

Unable to set Payload/Body on Google Cloud Tasks

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

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

  1. 发送 Http 方法 POST 实际上有效,但在 Cloud Tasks UI.

  2. 中显示为 GET
  3. 没有负载或 headers 被发送给工作人员或出现在 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)

来自 Google Cloud UI 的屏幕截图:

Empty headers

Empty payload

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

谢谢!

Thank You for this post, this is a bug in the existing Cloud Tasks UI and we are in the process of fixing this bug.

In the meantime the correct HTTP method of the task can be determined by running the following command:

gcloud beta tasks describe

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

The above command will show the correct HTTP method for the task.

答案来自:

您还可以使用获取任务的方法来获取更多信息。