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

如何将Zendesk接口curl语句转换为axios请求并解决EOF报错

Zendesk 密码重置接口curl转axios调整方案

错误原因说明

你遇到的EOF错误通常是请求格式不符合Zendesk接口要求,服务端主动提前断开连接导致,核心需要调整认证逻辑、请求头配置,同时排除跨域问题。

调整后的代码示例

场景1:使用API令牌认证(你当前代码使用的认证方式)

需要先确认你已在Zendesk后台开启API令牌访问权限:

try {
  const response = await axios.post(
    `https://${subdomain}.zendesk.com/api/v2/users/${userId}/password.json`,
    {
      "password": "12345678" // 需符合Zendesk密码规则:最少8位,无明显弱密码特征
    },
    {
      headers: {
        "Content-Type": "application/json"
      },
      auth: {
        username: `${email}/token`,
        password: ZENDESK_API_KEY
      }
    }
  )
  console.log('请求成功', response.data)
} catch (err) {
  // 打印完整错误信息定位问题
  console.error('请求失败', err.response?.data || err.message)
}

场景2:和原curl逻辑对齐,使用账号密码认证

try {
  const response = await axios.post(
    `https://${subdomain}.zendesk.com/api/v2/users/${userId}/password.json`,
    {
      "password": "12345678"
    },
    {
      headers: {
        "Content-Type": "application/json"
      },
      auth: {
        username: email,
        password: yourZendeskLoginPassword // 替换为你的Zendesk登录密码
      }
    }
  )
  console.log('请求成功', response.data)
} catch (err) {
  console.error('请求失败', err.response?.data || err.message)
}

额外排查项

  • 如果请求在浏览器端发起,Zendesk公共API默认不允许跨域,会触发连接断开,必须将请求移至后端服务发起
  • 确认你设置的密码符合Zendesk的复杂度要求,弱密码会被接口直接拒绝,也可能触发EOF错误

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 09:24:01