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

Remix Run中fetch返回空响应问题求助

解决方法

问题核心是**fetch返回的是Response对象,需要手动调用.json()方法解析响应体**。修改loadMerchantInfo函数如下:

const insecureAgent = new https.Agent({
  rejectUnauthorized: false,
})
export const loadMerchantInfo = async (cookie: string, options?: any) => {
  const actualOptions = options
    ? {
        ...options,
      }
    : ({} as RequestInit)
  if (process.env.NODE_ENV !== 'production') {
    actualOptions.agent = insecureAgent
    const headers = actualOptions.headers
      ? {
          ...options.headers,
          cookie,
          accept: 'application/json',
        }
      : {
          cookie,
          accept: 'application/json',
        }
    actualOptions.headers = headers
  }
  // 先获取Response对象
  const response = await fetch('[Internal URL] ', actualOptions)
  // 校验请求是否成功(可选但推荐)
  if (!response.ok) {
    throw new Error(`请求失败,状态码:${response.status}`)
  }
  // 解析响应体为JSON
  return await response.json()
}

修改后,merchantData会变为解析后的JSON对象,你可以根据需要在Loader函数中替换硬编码的返回值为return merchantData(需确保结构符合UnderwritingMerchantInfo类型)。


内容的提问来源于stack exchange,提问作者Jared Lee Jardine

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 00:45:36