You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用fetch结合Adobe认证无法获取请求JSON响应体,返回200但无实际内容

问题解决:node-fetch获取Adobe API响应体失败

你看到的[Symbol(Response internals)]是node-fetch返回的Response对象本身,并不是实际的响应体内容。fetch API不会自动解析响应体,必须调用对应的方法来提取数据。另外你的代码里还有一个参数格式错误:Content-Type应该放在headers对象里,而不是和method平级。

修正后的代码

如果响应是JSON格式(Postman中显示的是JSON),用.json()方法解析:

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

fetch(url, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'x-gw-ims-org-id': org_id,
        'x-api-key': api_key,
        'Authorization': `Bearer ${accessToken}`, 
    },
})
.then((response) => {
    // 先确认响应状态正常
    if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
    }
    // 解析JSON格式的响应体
    return response.json();
})
.then((data) => {
    // 这里才是实际的响应体内容
    console.log(data);
    // 如果需要保存到文件
    fs.writeFileSync('response.json', JSON.stringify(data, null, 2));
})
.catch((error) => console.log(error));

如果响应是纯文本格式,替换.json()为.text()即可:

return response.text();

关键说明

  • fetch返回的Response是一个流对象,必须调用.json()/.text()/.blob()等方法来读取并解析内容
  • 一定要先检查response.ok或response.status,避免在实际请求逻辑失败(比如状态码200但内容不符合预期)时继续解析
  • 原代码中Content-Type的位置错误,GET请求即便不需要该头,若API明确要求,也必须放在headers对象内

内容的提问来源于stack exchange,提问作者Jian Ruiz Mangampo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 01:45:30