Error: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body

Error: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body

我正在使用 fetch 调用 Google TimeZone。但是当我尝试将 lat/lng 和时间戳作为正文参数传递时出现错误。

Error: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body

这是我的代码。 Google 允许这样调用吗?

const data = new FormData();
data.append('location', this.latitude.value + ',' + this.longitude.value);
data.append('timestamp', Math.floor(Date.now() / 1000).toString());
data.append('key', 'my google API key')
const timeZoneResult = await fetch('https://maps.googleapis.com/maps/api/timezone/json', {
  method: 'GET',
  headers: {},
  body: data,
});
const timeZone = await timeZoneResult.json();

这样,全部在 url 字符串中,工作正常!

https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810%2C-119.6822510&timestamp=1331161200&key=myKeyHere

错误说明问题出在哪里。方法 GET 不能有主体。将数据作为查询字符串。

https://maps.googleapis.com/maps/api/timezone/json?location=...&timestamp=...