这两个请求有什么区别?

What's the difference between these two requests?

为什么第一个请求return200,

fetch("https://api.peopledatalabs.com/v5/autocomplete?api_key=someAPIKey&field=location")

但是第二个 returns 400/401?

fetch(`https://api.peopledatalabs.com/v5/autocomplete`, {
    "api_key": "someAPIKey",
    "field": "location"
    });

在第二种方式中,您传递了 option 参数(带有“api_key”和“字段”),而不是您所指的 queryParams。

您可以使用 URLSearchParams

将其更改为正常工作
fetch('https://api.peopledatalabs.com/v5/autocomplete?' + new URLSearchParams({
    api_key: "someAPIKey",
    field: "location",
}))