我正在使用 fetch 来调用 Google TimeZone。但是当我尝试将 lat/lng 和时间戳作为正文参数传递时,出现错误。
错误:无法在“窗口”上执行“获取”:使用 GET/HEAD 方法的请求不能有正文
这是我的代码。 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 字符串中,工作正常!
错误指出问题出在哪里。方法 GET 不能有主体。将数据作为查询字符串放置。
https://maps.googleapis.com/maps/api/timezone/json?location=...×tamp=...