无法获取请求的JSON主体

k4ymrczo  于 2022-12-15  发布在  其他
关注(0)|答案(1)|浏览(112)

尝试使用fetch和adobe的身份验证来获取body的body。我总是得到这个200的响应(意味着没问题),但是我不能像在postman中那样得到body的实际响应。

[Symbol(Response internals)]: {
    url: url_of_adobe,
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }

这是我的密码

const fetch = require("node-fetch");
const fs = require("fs");

fetch(url, {
    'method': 'GET',
    'Content-Type': 'application/json',
    'headers': {
        'x-gw-ims-org-id': org_id,
        'x-api-key': api_key,
        'Authorization': `Bearer ${accessToken}`, 
    },
    
}).then((response) => console.log(response))
    .catch((error) => console.log(error));
e0bqpujr

e0bqpujr1#

内容类型应位于标头中

'headers': {
        'Content-Type': 'application/json',
        'x-gw-ims-org-id': org_id,
        'x-api-key': api_key,
        'Authorization': `Bearer ${accessToken}`, 
    },

如果你想读取json格式的响应,你必须对响应使用.json()

.then((response) => console.log(response.json()))
    .catch((error) => console.log(error));

相关问题