我正在尝试使用JSON API创建GCP云存储桶并出现以下错误

时间:2020-09-30 22:15:59

标签: api google-cloud-platform restapi

curl --request POST
'https://storage.googleapis.com/storage/v1/b?project=&key=[YOUR_API_KEY]'
--header'授权:承载[YOUR_ACCESS_TOKEN]'
--header'接受:application / json'
--header'Content-Type:application / json'
--data'{“ name”:“”}'
-压缩

错误消息:

{ “错误”:{ “代码”:400, “ message”:“ CORS请求包含X-Origin标头”, “错误”:[ { “ message”:“ CORS请求包含X-Origin标头”, “ domain”:“ global”, “ reason”:“ corsRequestWithXOrigin” } ] } }

1 个答案:

答案 0 :(得分:1)

如果使用访问令牌,则可以删除API密钥。我个人遵循the documentation并进行了重播,它奏效了

curl --request POST 'https://storage.googleapis.com/storage/v1/b?project=[YOUR_PROJECT_ID]' \
  --header "Authorization: Bearer  [YOUR_ACCESS_TOKEN]" \
  --header 'Accept: application/json' --header 'Content-Type: application/json' \
  --data '{"name":"[MY_BUCKET_NAME]"}' --compressed