使用 JavaScript 获取 API 请求无法在控制台中显示数据,但在 POSTMAN 中可以正常工作

问题描述 投票:0回答:1

我没有通过请求此 API 在控制台中获取 JSON 数据:https://amlocatapi.us-south.cf.appdomain.cloud/location 使用此标头

{
  method:'GET',
  headers:{
    'Authorization':'1q2w3e4r5t6yu7i8',
    'Content-Type':'application/json'
  }
}

<html>
<head></head>
<body>
Hello
</body>
<script>
fetch('https://amlocatapi.us-south.cf.appdomain.cloud/location',
{
  method:'GET',
  headers:{
    'Authorization':'1q2w3e4r5t6yu7i8',
    'Content-Type':'application/json'
  }
}
).then(response => response.json())
.then(json => console.log(json))
.catch(err => console.log(err));
</script>

</html>

javascript postman fetch-api request-headers
1个回答
0
投票

尝试删除

'Content-Type': 'application/json'
标题。由于您正在发出 GET 请求,因此不需要它。控制台的响应是什么?您检查了网络请求吗?

© www.soinside.com 2019 - 2024. All rights reserved.