跳到主要内容

NextJS(fetch)

使用 Proxyman 自动设置中预配置的终端,抓包 Next.js 服务端 fetch() 和 Server Components 的 HTTPS 请求。

1. 问题​

  • Proxyman 无法抓取 NextJS 中 use server 代码的任何流量
  • 这是因为 NextJS 中的 fetch 不遵循系统 HTTP 代理设置,因此没有流量会经过 Proxyman 应用。

2. 解决方案​

  1. 启动预配置的终端:Setup 菜单 -> Automatic Setup -> 点击 “Open New Terminal”
  2. 会打开一个新的终端 -> 在此终端中启动你的 NextJS 服务器。例如:npm run dev
  3. 在 fetch 上使用 no-cache
export default async function MyPage() {
const res = await fetch('https://httpbin.org/anything', { cache: 'no-cache' }) // no cache, or no request is sent to Proxyman
return <div>My Page{res.text()}</div>
}
  1. 重新加载你的网站
  2. 完成 ✅ Proxyman 应用会抓取你的 HTTP 流量
Proxyman 预配置终端中运行的 Next.js 开发服务器,以及 Proxyman 中抓取到的服务端 fetch 请求

在 Proxyman 中抓取 NextJS 的 fetch 请求

3. 参考资料​

了解更多​