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

Express中res.send/res.json无响应体,客户端仅获ReadableStream求助

问题:Express返回数据客户端无法获取实际内容

问题现象

  • Node服务器通过第三方API获取到用户订单数据后,用console.log可以正常打印完整的订单结构:
{"customer":{"orders":{"edges":[{"node":{"id":"gid://shopify/Order/1234564564","lineItems":{"edges":[{"node":{"title":"Some title here"}}]}}}]}}}
  • 但调用res.send或res.json把数据返回给客户端时,客户端在开发者工具中打印响应,得到的是一个ReadableStream对象,看不到实际的返回内容:
body:ReadableStream
  locked:false
  [[Prototype]]:ReadableStream
bodyUsed:false
headers: 
   Headers {}
ok:true
redirected:false
status:200
statusText:"OK"
type:"basic"
url:"http://localhost:9000/api/getOrders?cid=gid://shopify/Customer/1234564564"
[[Prototype]]:Response
  • 即使测试最基础的接口,客户端得到的响应类型还是一样:
app.get('/testExpress', (req, res) => {
  res.send("Hello")
});

解决方法

客户端使用fetch发起请求时,必须调用响应对象的解析方法来读取实际内容。比如用text()解析文本格式,或者用json()解析JSON格式:

fetch('/testExpress')
  .then(async (response) => {
    const content = await response.text();
    console.log(content);
  })

内容的提问来源于stack exchange,提问作者gregwhitworth

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 11:45:44