长时间运行的操作

Submission API 是异步进行的,并返回长时间运行的操作。当方法返回响应时,操作可能尚未完成。

获取操作状态

下面介绍了如何轮询操作的状态。

对操作类型调用 GET 方法。

在使用任何请求数据之前,请先进行以下替换:

  • project-number:您的 Google Cloud 项目编号
  • operation-id:您的操作 ID

HTTP 方法和网址:

GET https://webrisk.googleapis.com/v1/projects/project-number/operations/operation-id

如需发送请求,请选择以下方式之一:

curl

执行以下命令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
"https://webrisk.googleapis.com/v1/projects/project-number/operations/operation-id"

PowerShell

执行以下命令:

$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://webrisk.googleapis.com/v1/projects/project-number/operations/operation-id" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/project-number/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.webrisk.v1.SubmitUriMetadata",
    "state": "RUNNING"
  }
  "done": false,
  ...
}

操作完成后,系统将为 state 返回以下值之一:

  • SUCCEEDED:表示提交的网址已添加到“安全浏览”屏蔽名单中。

  • CLOSED:表示所提交的网址未被检测到违反安全浏览政策,并且在过去 24 小时内未添加到安全浏览屏蔽名单中。